//! Error types for the edifact-mapper facade crate.

/// Errors that can occur when using the [`Mapper`](crate::Mapper) API.
#[derive(Debug, thiserror::Error)]
pub enum MapperError {
    /// The specified data directory does not exist on disk.
    #[error("Data directory not found: {path}")]
    DataDirNotFound { path: String },

    /// No data bundle file found for the requested format version.
    #[error("No data bundle found for format version {fv}")]
    BundleNotFound { fv: String },

    /// The requested variant (e.g., "UTILMD_Strom") is not present in the bundle.
    #[error("No variant '{variant}' in bundle for {fv}")]
    VariantNotFound { fv: String, variant: String },

    /// No mapping engine definitions exist for the given PID within the variant.
    #[error("No mapping engine for PID {pid} in {fv}/{variant}")]
    PidNotFound {
        fv: String,
        variant: String,
        pid: String,
    },

    /// An error from the MIG assembly layer.
    #[error("Assembly error: {0}")]
    Assembly(#[from] mig_assembly::AssemblyError),

    /// An error from the TOML mapping engine.
    #[error("Mapping error: {0}")]
    Mapping(#[from] mig_bo4e::MappingError),

    /// JSON serialization failed (e.g., when converting a typed struct to JSON).
    #[error("Serialization error: {0}")]
    Serialization(String),

    /// The variant has no MIG schema (required for reverse pipeline).
    #[error("No MIG schema for {fv}/{variant}")]
    NoMigSchema { fv: String, variant: String },

    /// A standard I/O error.
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),
}
