//! Full-chain verification for `EvidenceKind::ComplianceEvidence`.

mod common;

use chrono::{Duration, Utc};
use cortex_core::ClaimCeiling;
use cortex_verifier::{verify, VerifiedTrustState, WitnessClass, WITNESS_TIER_INSUFFICIENT};

use crate::common::{
    advisory_only_input, authority_grade_input, full_witness_set, sample_evidence_digest,
    signed_witness, Kind,
};

#[test]
fn compliance_evidence_full_chain_promotes_to_authority_grade() {
    let digest = sample_evidence_digest();
    let now = Utc::now();
    let witnesses = full_witness_set(&digest, now);

    let state = verify(
        &authority_grade_input(Kind::ComplianceEvidence),
        &witnesses,
        now,
        Duration::seconds(86_400),
    );

    match state {
        VerifiedTrustState::FullChainVerified { ceiling, witnesses } => {
            assert_eq!(ceiling, ClaimCeiling::AuthorityGrade);
            assert_eq!(witnesses.len(), 4);
        }
        other => panic!("expected FullChainVerified, got {other:?}"),
    }
}

#[test]
fn compliance_evidence_advisory_only_stays_advisory_even_with_witnesses() {
    let digest = sample_evidence_digest();
    let now = Utc::now();
    let witnesses = full_witness_set(&digest, now);

    let state = verify(
        &advisory_only_input(Kind::ComplianceEvidence),
        &witnesses,
        now,
        Duration::seconds(86_400),
    );

    match state {
        VerifiedTrustState::Broken { edge, .. } => {
            assert_eq!(edge.invariant, WITNESS_TIER_INSUFFICIENT);
        }
        other => panic!("expected advisory_only -> Broken(tier_insufficient), got {other:?}"),
    }
}

#[test]
fn compliance_evidence_local_signed_ledger_only_is_partial() {
    let digest = sample_evidence_digest();
    let now = Utc::now();
    let witnesses = vec![signed_witness(
        1,
        WitnessClass::SignedLedgerChainHead,
        cortex_verifier::WitnessTier::OperatorOwned,
        &digest,
        now,
    )];

    let state = verify(
        &authority_grade_input(Kind::ComplianceEvidence),
        &witnesses,
        now,
        Duration::seconds(86_400),
    );

    assert!(state.is_partial(), "got {state:?}");
}
