#![expect(
    clippy::disallowed_types,
    reason = "EngineRequirement requires Any for its downcast handle."
)]

use std::any::Any;

use aqc_file_engine_core::{EngineRequirement, Provenance};
use g3rs_core::{EngineRequirementOutput, EngineRequirementOutputItem, boxed_engine_requirement};
use serde_json as _;

#[derive(Debug)]
struct DummyRequirement;

impl EngineRequirement for DummyRequirement {
    fn engine_id(&self) -> &'static str {
        "dummy-engine"
    }

    fn as_any(&self) -> &dyn Any {
        self
    }
}

#[test]
fn boxed_engine_requirement_preserves_provenance_and_engine_requirement() {
    let provenance = Provenance {
        policy: "policy".to_owned(),
    };
    let item: EngineRequirementOutputItem =
        boxed_engine_requirement(provenance.clone(), DummyRequirement);
    let output: EngineRequirementOutput = vec![item];

    assert_eq!(output.len(), 1, "one engine requirement should be emitted");
    let Some((actual_provenance, requirement)) = output.first() else {
        assert_eq!(output.len(), 1, "one engine requirement should be emitted");
        return;
    };
    assert_eq!(
        actual_provenance, &provenance,
        "provenance should be preserved"
    );
    assert_eq!(
        requirement.engine_id(),
        "dummy-engine",
        "boxed requirement should remain dispatchable"
    );
}
