use fuzzy_parser::Correction;

/// Successful extraction result with metadata.
///
/// Returned by [`extract_verbose`](crate::extract_verbose) and
/// [`Extractor::extract_verbose`](crate::Extractor::extract_verbose).
#[derive(Debug)]
pub struct Extracted<T> {
    /// The deserialized value.
    pub value: T,
    /// Corrections applied during repair. Empty if no repair was needed.
    pub corrections: Vec<Correction>,
}

/// Errors that can occur during extraction.
#[derive(Debug, thiserror::Error)]
pub enum ExtractError {
    /// No JSON entity found in the input text.
    #[error("no JSON found in input")]
    NotFound,

    /// JSON entity found but failed to parse after sanitization.
    #[error("JSON parse error: {source}")]
    Parse {
        /// The extracted (and possibly sanitized) JSON string.
        extracted: String,
        #[source]
        source: serde_json::Error,
    },

    /// Repair was attempted but deserialization still failed.
    #[error("repair failed: {source}")]
    RepairFailed {
        /// The JSON string after repair attempt.
        repaired: String,
        /// Corrections that were applied before failure.
        corrections: Vec<Correction>,
        #[source]
        source: serde_json::Error,
    },

    /// Input exceeds maximum allowed length.
    #[error("input too large: {len} bytes (max {max})")]
    InputTooLarge { len: usize, max: usize },
}
