//! Typed errors for the model-compatibility engine.
//!
//! Capture, diff, and invariant evaluation share one enum so callers
//! match on a small surface. The top-level [`crate::Error`] wraps this
//! enum so existing public APIs keep returning `crate::Result`.

use thiserror::Error;

/// Failure modes specific to the model-compatibility engine.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ModelCompatError {
    /// The runner produced no captured exchanges. Usually a `--filter`
    /// glob matched zero tests; surface as an error so the user is not
    /// surprised by an empty baseline file.
    #[error("capture produced no exchanges (filter matched nothing?)")]
    EmptyCapture,

    /// Two baselines reference incompatible schema versions and the
    /// diff engine refuses to compare them (ADR 0026 OQ-2).
    #[error("incompatible baseline versions: {a} vs {b}")]
    IncompatibleVersions {
        /// Schema version of the first baseline file.
        a: u32,
        /// Schema version of the second baseline file.
        b: u32,
    },

    /// An I/O failure while reading or writing a baseline file.
    #[error("io: {0}")]
    Io(#[from] std::io::Error),

    /// A baseline file failed to (de)serialize as JSON.
    #[error("json: {0}")]
    Json(#[from] serde_json::Error),

    /// A capture filter glob did not parse.
    #[error("invalid filter pattern '{pattern}': {reason}")]
    InvalidFilter {
        /// The user-supplied glob.
        pattern: String,
        /// A short reason the engine could not compile it.
        reason: String,
    },
}
