use serde::Serialize;

#[derive(Debug, thiserror::Error)]
pub enum TuskError {
    #[error("Database error: {0}")]
    Database(#[from] sqlx::Error),

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

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

    #[error("Not connected: {0}")]
    NotConnected(String),

    #[error("Connection is in read-only mode")]
    ReadOnly,

    #[error("AI error: {0}")]
    Ai(String),

    #[error("Configuration error: {0}")]
    Config(String),

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

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

    #[error("{0}")]
    Custom(String),
}

impl Serialize for TuskError {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(&self.to_string())
    }
}

pub type TuskResult<T> = Result<T, TuskError>;
