use rpki::policy::{CaFailedFetchPolicy, Policy, SignedObjectFailurePolicy, SyncPreference};

#[test]
fn policy_defaults_are_correct() {
    let p = Policy::default();
    assert_eq!(p.sync_preference, SyncPreference::RrdpThenRsync);
    assert_eq!(
        p.ca_failed_fetch_policy,
        CaFailedFetchPolicy::ReuseCurrentInstanceVcir
    );
    assert_eq!(
        p.signed_object_failure_policy,
        SignedObjectFailurePolicy::DropObject
    );
}

#[test]
fn policy_toml_parsing_supports_overrides() {
    let toml = r#"
sync_preference = "rsync_only"
ca_failed_fetch_policy = "stop_all_output"
signed_object_failure_policy = "drop_publication_point"
"#;
    let p = Policy::from_toml_str(toml).expect("parse TOML policy");
    assert_eq!(p.sync_preference, SyncPreference::RsyncOnly);
    assert_eq!(p.ca_failed_fetch_policy, CaFailedFetchPolicy::StopAllOutput);
    assert_eq!(
        p.signed_object_failure_policy,
        SignedObjectFailurePolicy::DropPublicationPoint
    );
}

#[test]
fn policy_toml_parsing_accepts_reuse_current_instance_vcir() {
    let toml = r#"ca_failed_fetch_policy = "reuse_current_instance_vcir"
"#;
    let p = Policy::from_toml_str(toml).expect("parse TOML policy");
    assert_eq!(
        p.ca_failed_fetch_policy,
        CaFailedFetchPolicy::ReuseCurrentInstanceVcir
    );
}

#[test]
fn policy_toml_parsing_uses_defaults_when_missing() {
    let p = Policy::from_toml_str("").expect("parse empty TOML policy");
    assert_eq!(p, Policy::default());
}
