mod compositions;
mod coverage;
pub mod dsl;

use crate::{CompositionSchema, MachineSchema};
use crate::{RustBinding, identity::MachineId};

// Canonical exposures for the two-kernel cutover
pub use compositions::{
    adaptive_mob_bundle_composition, auth_lease_bundle_composition, meerkat_mob_seam_composition,
    schedule_bundle_composition, schedule_mob_bundle_composition,
    schedule_runtime_bundle_composition, workgraph_attention_bundle_composition,
};
pub use coverage::{
    CompositionCoverageManifest, CoverageAnchor, CoverageClaims, CoverageSchemaTarget,
    MachineCoverageManifest, ScenarioCoverage, SemanticCoverageEntry, SymbolRef,
    canonical_composition_coverage_manifests, canonical_machine_coverage_manifests,
    scheduler_rule_coverage_name,
};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MachineProductionOwnerRelation {
    pub machine: MachineId,
    pub rust: RustBinding,
}

impl MachineProductionOwnerRelation {
    pub fn new(machine: &str, crate_name: &str, module: &str) -> Self {
        Self {
            #[allow(clippy::expect_used)]
            machine: MachineId::parse(machine).expect("valid machine id"),
            rust: RustBinding {
                crate_name: crate_name.to_owned(),
                module: module.to_owned(),
            },
        }
    }
}

pub fn canonical_machine_schemas() -> Vec<MachineSchema> {
    vec![
        dsl::dsl_meerkat_machine(),
        dsl::dsl_mob_machine(),
        dsl::dsl_schedule_lifecycle_machine(),
        dsl::dsl_occurrence_lifecycle_machine(),
        dsl::dsl_auth_machine(),
        dsl::dsl_approval_lifecycle_machine(),
        dsl::dsl_session_document_machine(),
        dsl::dsl_session_turn_admission_machine(),
        dsl::dsl_workgraph_lifecycle_machine(),
        dsl::dsl_work_attention_lifecycle_machine(),
    ]
}

pub fn canonical_composition_schemas() -> Vec<CompositionSchema> {
    vec![
        meerkat_mob_seam_composition(),
        schedule_bundle_composition(),
        schedule_runtime_bundle_composition(),
        schedule_mob_bundle_composition(),
        adaptive_mob_bundle_composition(),
        auth_lease_bundle_composition(),
        workgraph_attention_bundle_composition(),
    ]
}

pub fn canonical_machine_production_owner_relations() -> Vec<MachineProductionOwnerRelation> {
    vec![
        MachineProductionOwnerRelation::new(
            "MeerkatMachine",
            dsl::MEERKAT_MACHINE_PRODUCTION_RUST_CRATE,
            dsl::MEERKAT_MACHINE_PRODUCTION_RUST_MODULE,
        ),
        MachineProductionOwnerRelation::new(
            "AuthMachine",
            dsl::AUTH_MACHINE_PRODUCTION_RUST_CRATE,
            dsl::AUTH_MACHINE_PRODUCTION_RUST_MODULE,
        ),
        MachineProductionOwnerRelation::new(
            "ApprovalLifecycleMachine",
            dsl::APPROVAL_LIFECYCLE_PRODUCTION_RUST_CRATE,
            dsl::APPROVAL_LIFECYCLE_PRODUCTION_RUST_MODULE,
        ),
        MachineProductionOwnerRelation::new(
            "SessionDocumentMachine",
            dsl::SESSION_DOCUMENT_PRODUCTION_RUST_CRATE,
            dsl::SESSION_DOCUMENT_PRODUCTION_RUST_MODULE,
        ),
        MachineProductionOwnerRelation::new(
            "SessionTurnAdmissionMachine",
            dsl::SESSION_TURN_ADMISSION_PRODUCTION_RUST_CRATE,
            dsl::SESSION_TURN_ADMISSION_PRODUCTION_RUST_MODULE,
        ),
        MachineProductionOwnerRelation::new(
            "MobMachine",
            dsl::MOB_MACHINE_PRODUCTION_RUST_CRATE,
            dsl::MOB_MACHINE_PRODUCTION_RUST_MODULE,
        ),
        MachineProductionOwnerRelation::new(
            "ScheduleLifecycleMachine",
            dsl::SCHEDULE_LIFECYCLE_PRODUCTION_RUST_CRATE,
            dsl::SCHEDULE_LIFECYCLE_PRODUCTION_RUST_MODULE,
        ),
        MachineProductionOwnerRelation::new(
            "OccurrenceLifecycleMachine",
            dsl::OCCURRENCE_LIFECYCLE_PRODUCTION_RUST_CRATE,
            dsl::OCCURRENCE_LIFECYCLE_PRODUCTION_RUST_MODULE,
        ),
        MachineProductionOwnerRelation::new(
            "WorkGraphLifecycleMachine",
            dsl::WORKGRAPH_LIFECYCLE_PRODUCTION_RUST_CRATE,
            dsl::WORKGRAPH_LIFECYCLE_PRODUCTION_RUST_MODULE,
        ),
        MachineProductionOwnerRelation::new(
            "WorkAttentionLifecycleMachine",
            dsl::WORK_ATTENTION_LIFECYCLE_PRODUCTION_RUST_CRATE,
            dsl::WORK_ATTENTION_LIFECYCLE_PRODUCTION_RUST_MODULE,
        ),
    ]
}
