use thiserror::Error;

#[derive(Error, Debug)]
pub enum FurnaceError {
    #[error("Database error: {0}")]
    Database(#[from] rusqlite::Error),

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

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

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

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

    #[error("Agent error: {agent} - {message}")]
    Agent { agent: String, message: String },

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

    #[error("Scroll not found: {0}")]
    ScrollNotFound(String),

    #[error("Task not found: {0}")]
    TaskNotFound(String),

    #[error("Budget exceeded: daily budget of ${budget:.2} exceeded")]
    BudgetExceeded { budget: f64 },

    #[error("Timeout: operation exceeded {timeout_ms}ms")]
    Timeout { timeout_ms: u64 },

    #[error("LLM provider error: {0}")]
    LlmProvider(String),

    #[error("Graph query error: {0}")]
    GraphQuery(String),

    #[error("Recipe not found: {0}")]
    RecipeNotFound(String),

    #[error("Knowledge base error ({kb_source}): {message}")]
    KnowledgeBase { kb_source: String, message: String },

    #[error("Knowledge base not configured: {0}")]
    KBNotConfigured(String),

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

pub type Result<T> = std::result::Result<T, FurnaceError>;
