use pixstrip_core::operations::*;
use pixstrip_core::types::*;

#[test]
fn resize_config_width_only() {
    let config = ResizeConfig::ByWidth(1200);
    assert_eq!(
        config.target_for(Dimensions { width: 4000, height: 3000 }),
        Dimensions { width: 1200, height: 900 }
    );
}

#[test]
fn resize_config_fit_in_box() {
    let config = ResizeConfig::FitInBox {
        max: Dimensions { width: 1920, height: 1080 },
        allow_upscale: false,
    };
    let result = config.target_for(Dimensions { width: 4000, height: 3000 });
    assert_eq!(result.width, 1440);
    assert_eq!(result.height, 1080);
}

#[test]
fn resize_config_exact() {
    let config = ResizeConfig::Exact(Dimensions { width: 1080, height: 1080 });
    assert_eq!(
        config.target_for(Dimensions { width: 4000, height: 3000 }),
        Dimensions { width: 1080, height: 1080 }
    );
}

#[test]
fn metadata_config_strip_all() {
    let config = MetadataConfig::StripAll;
    assert!(config.should_strip_gps());
    assert!(config.should_strip_camera());
    assert!(config.should_strip_copyright());
}

#[test]
fn metadata_config_privacy() {
    let config = MetadataConfig::Privacy;
    assert!(config.should_strip_gps());
    assert!(config.should_strip_camera());
    assert!(!config.should_strip_copyright());
}

#[test]
fn metadata_config_keep_all() {
    let config = MetadataConfig::KeepAll;
    assert!(!config.should_strip_gps());
    assert!(!config.should_strip_camera());
    assert!(!config.should_strip_copyright());
}

#[test]
fn convert_config_single_format() {
    let config = ConvertConfig::SingleFormat(ImageFormat::WebP);
    assert_eq!(config.output_format(ImageFormat::Jpeg), ImageFormat::WebP);
    assert_eq!(config.output_format(ImageFormat::Png), ImageFormat::WebP);
}

#[test]
fn convert_config_keep_original() {
    let config = ConvertConfig::KeepOriginal;
    assert_eq!(config.output_format(ImageFormat::Jpeg), ImageFormat::Jpeg);
    assert_eq!(config.output_format(ImageFormat::Png), ImageFormat::Png);
}

#[test]
fn watermark_position_all_nine() {
    let positions = [
        WatermarkPosition::TopLeft,
        WatermarkPosition::TopCenter,
        WatermarkPosition::TopRight,
        WatermarkPosition::MiddleLeft,
        WatermarkPosition::Center,
        WatermarkPosition::MiddleRight,
        WatermarkPosition::BottomLeft,
        WatermarkPosition::BottomCenter,
        WatermarkPosition::BottomRight,
    ];
    assert_eq!(positions.len(), 9);
}

#[test]
fn rename_config_simple_template() {
    let config = RenameConfig {
        prefix: "blog_".into(),
        suffix: String::new(),
        counter_start: 1,
        counter_padding: 3,
        counter_enabled: true,
        counter_position: 3,
        template: None,
        case_mode: 0,
        replace_spaces: 0,
        special_chars: 0,
        regex_find: String::new(),
        regex_replace: String::new(),
    };
    let result = config.apply_simple("sunset", "jpg", 1);
    assert_eq!(result, "blog_sunset_001.jpg");
}

#[test]
fn rename_config_with_suffix() {
    let config = RenameConfig {
        prefix: String::new(),
        suffix: "_web".into(),
        counter_start: 1,
        counter_padding: 2,
        counter_enabled: true,
        counter_position: 3,
        template: None,
        case_mode: 0,
        replace_spaces: 0,
        special_chars: 0,
        regex_find: String::new(),
        regex_replace: String::new(),
    };
    let result = config.apply_simple("photo", "webp", 5);
    assert_eq!(result, "photo_web_05.webp");
}

#[test]
fn rename_counter_overflow_saturates() {
    let config = RenameConfig {
        prefix: String::new(),
        suffix: String::new(),
        counter_start: u32::MAX,
        counter_padding: 1,
        counter_enabled: true,
        counter_position: 3,
        template: None,
        case_mode: 0,
        replace_spaces: 0,
        special_chars: 0,
        regex_find: String::new(),
        regex_replace: String::new(),
    };
    // Should not panic - saturating arithmetic
    let result = config.apply_simple("photo", "jpg", u32::MAX);
    assert!(result.contains("photo"));
}

#[test]
fn metadata_config_custom_selective() {
    let config = MetadataConfig::Custom {
        strip_gps: true,
        strip_camera: false,
        strip_software: true,
        strip_timestamps: false,
        strip_copyright: false,
    };
    assert!(config.should_strip_gps());
    assert!(!config.should_strip_camera());
    assert!(!config.should_strip_copyright());
}

#[test]
fn metadata_config_custom_all_off() {
    let config = MetadataConfig::Custom {
        strip_gps: false,
        strip_camera: false,
        strip_software: false,
        strip_timestamps: false,
        strip_copyright: false,
    };
    assert!(!config.should_strip_gps());
    assert!(!config.should_strip_camera());
    assert!(!config.should_strip_copyright());
}

#[test]
fn metadata_config_custom_all_on() {
    let config = MetadataConfig::Custom {
        strip_gps: true,
        strip_camera: true,
        strip_software: true,
        strip_timestamps: true,
        strip_copyright: true,
    };
    assert!(config.should_strip_gps());
    assert!(config.should_strip_camera());
    assert!(config.should_strip_copyright());
}

#[test]
fn watermark_rotation_variants_exist() {
    let rotations = [
        WatermarkRotation::Degrees45,
        WatermarkRotation::DegreesNeg45,
        WatermarkRotation::Degrees90,
        WatermarkRotation::Custom(30.0),
    ];
    assert_eq!(rotations.len(), 4);
}

#[test]
fn rotation_auto_orient_variant() {
    let rotation = Rotation::AutoOrient;
    assert!(matches!(rotation, Rotation::AutoOrient));
}

#[test]
fn overwrite_action_default_is_auto_rename() {
    let default = OverwriteAction::default();
    assert!(matches!(default, OverwriteAction::AutoRename));
}
