use pixstrip_core::preset::*;
use pixstrip_core::operations::*;

#[test]
fn builtin_preset_blog_photos() {
    let preset = Preset::builtin_blog_photos();
    assert_eq!(preset.name, "Blog Photos");
    assert!(preset.resize.is_some());
    assert!(preset.compress.is_some());
    assert!(preset.metadata.is_some());
    assert!(!preset.is_custom);
}

#[test]
fn builtin_preset_privacy_clean() {
    let preset = Preset::builtin_privacy_clean();
    assert_eq!(preset.name, "Privacy Clean");
    assert!(preset.resize.is_none());
    assert!(preset.compress.is_none());
    assert!(preset.metadata.is_some());
    if let Some(MetadataConfig::StripAll) = &preset.metadata {
        // correct
    } else {
        panic!("Expected StripAll metadata config");
    }
}

#[test]
fn preset_serialization_roundtrip() {
    let preset = Preset::builtin_blog_photos();
    let json = serde_json::to_string_pretty(&preset).unwrap();
    let deserialized: Preset = serde_json::from_str(&json).unwrap();
    assert_eq!(deserialized.name, preset.name);
    assert_eq!(deserialized.is_custom, preset.is_custom);
}

#[test]
fn all_builtin_presets() {
    let presets = Preset::all_builtins();
    assert_eq!(presets.len(), 9);
    let names: Vec<&str> = presets.iter().map(|p| p.name.as_str()).collect();
    assert!(names.contains(&"Blog Photos"));
    assert!(names.contains(&"Social Media"));
    assert!(names.contains(&"Web Optimization"));
    assert!(names.contains(&"Email Friendly"));
    assert!(names.contains(&"Privacy Clean"));
    assert!(names.contains(&"Photographer Export"));
    assert!(names.contains(&"Archive Compress"));
    assert!(names.contains(&"Fediverse Ready"));
}

#[test]
fn preset_to_processing_job() {
    let preset = Preset::builtin_blog_photos();
    let job = preset.to_job("/tmp/input/", "/tmp/output/");
    assert!(job.resize.is_some());
    assert!(job.compress.is_some());
    assert!(job.metadata.is_some());
}
