use rpki::data_model::aspa::{AspaDecodeError, AspaObject, AspaProfileError};
use rpki::data_model::signed_object::RpkiSignedObject;

#[test]
fn decode_aspa_fixture_smoke() {
    let der = std::fs::read(
        "tests/fixtures/repository/chloe.sobornost.net/rpki/RIPE-nljobsnijders/5m80fwYws_3FiFD7JiQjAqZ1RYQ.asa",
    )
    .expect("read ASPA fixture");
    let aspa = AspaObject::decode_der(&der).expect("decode aspa");
    aspa.validate_profile().expect("validate ASPA profile");
    assert_eq!(aspa.econtent_type, rpki::data_model::oid::OID_CT_ASPA);
    assert_eq!(aspa.aspa.version, 1);
    assert_ne!(aspa.aspa.customer_as_id, 0);
    assert!(!aspa.aspa.provider_as_ids.is_empty());
    println!("{aspa:#?}");
}

#[test]
fn from_signed_object_accepts_aspa_fixture() {
    let der = std::fs::read(
        "tests/fixtures/repository/chloe.sobornost.net/rpki/RIPE-nljobsnijders/5m80fwYws_3FiFD7JiQjAqZ1RYQ.asa",
    )
    .expect("read ASPA fixture");
    let so = RpkiSignedObject::decode_der(&der).expect("decode signed object");
    let aspa = AspaObject::from_signed_object(so).expect("from_signed_object");
    aspa.validate_profile().expect("validate ASPA profile");
}

#[test]
fn decode_rejects_non_aspa_econtent_type() {
    let der = std::fs::read("tests/fixtures/repository/rpki.cernet.net/repo/cernet/0/AS4538.roa")
        .expect("read ROA fixture");
    let err = AspaObject::decode_der(&der).unwrap_err();
    assert!(matches!(
        err,
        AspaDecodeError::Validate(AspaProfileError::InvalidEContentType(_))
    ));
}
