//! Error types for file operations.

use std::path::PathBuf;

/// Errors that can occur when working with configuration files.
#[derive(Debug, thiserror::Error)]
pub enum FileError {
    /// IO error occurred.
    #[error("io error: {0}")]
    Io(#[from] std::io::Error),

    /// File not found in any search location.
    #[error("config file not found: searched in {locations}")]
    NotFound {
        /// The file pattern that was searched for.
        pattern: String,
        /// Locations that were searched.
        locations: String,
    },

    /// Parse error for a specific format.
    #[error("failed to parse {format} file at {path}: {source}")]
    Parse {
        /// Path to the file.
        path: PathBuf,
        /// Format that failed to parse.
        format: &'static str,
        /// Original error.
        source: Box<dyn std::error::Error + Send + Sync>,
    },

    /// Format not supported (feature not enabled).
    #[error("format '{format}' not supported (feature not enabled)")]
    UnsupportedFormat {
        /// The unsupported format.
        format: String,
    },

    /// Serialization error.
    #[error("serialization error: {0}")]
    Serialization(String),
}

/// Result type alias for file operations.
pub type Result<T> = std::result::Result<T, FileError>;
