//! `Adapter` contract impl for the rustc adapter.

use shackles_core::{
    Adapter, AdapterError, AdapterRequirement, EngineRequirementOutput, LinterCommand, Provenance,
};

use crate::runtime::build::lower_rustc_requirement;
use crate::types::{ADAPTER_ID, RustcAdapter, RustcAdapterRequirement};

impl Adapter for RustcAdapter {
    fn id(&self) -> &'static str {
        ADAPTER_ID
    }

    fn lower(
        &self,
        provenance: Provenance,
        requirement: Box<dyn AdapterRequirement>,
    ) -> Result<EngineRequirementOutput, AdapterError> {
        let Some(req) = requirement
            .as_any()
            .downcast_ref::<RustcAdapterRequirement>()
        else {
            return Err(AdapterError::WrongRequirementType {
                adapter_id: ADAPTER_ID,
                expected: "RustcAdapterRequirement",
            });
        };
        Ok(lower_rustc_requirement(provenance, req.clone()))
    }

    fn linter_command(&self) -> Option<LinterCommand> {
        None
    }

}
