//! Error types for the Rustelo framework

use thiserror::Error;

/// Main error type for Rustelo framework operations
#[derive(Error, Debug)]
pub enum RusteloError {
    #[error("Configuration error: {0}")]
    Config(String),

    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),

    #[error("Serialization error: {0}")]
    Serialization(#[from] serde_json::Error),

    #[cfg(feature = "http")]
    #[error("HTTP request error: {0}")]
    Http(#[from] reqwest::Error),

    #[error("Generic error: {0}")]
    Anyhow(#[from] anyhow::Error),

    #[error("Generic framework error: {0}")]
    Generic(String),
}

/// Convenience type alias for Results using RusteloError
pub type Result<T> = std::result::Result<T, RusteloError>;

impl RusteloError {
    /// Create a new configuration error
    pub fn config(msg: impl Into<String>) -> Self {
        Self::Config(msg.into())
    }

    /// Create a new generic error
    pub fn generic(msg: impl Into<String>) -> Self {
        Self::Generic(msg.into())
    }
}
