//! 统一错误类型定义

use thiserror::Error;

/// 统一错误类型
#[derive(Debug, Error)]
pub enum Error {
    #[error("未找到: {0}")]
    NotFound(String),

    #[error("已存在: {0}")]
    AlreadyExists(String),

    #[error("验证失败: {0}")]
    Validation(String),

    #[error("状态错误: 当前状态 {current}, 期望 {expected}")]
    InvalidState {
        current: String,
        expected: String,
    },

    #[error("工作流错误: {0}")]
    Workflow(String),

    #[error("执行错误: {0}")]
    Execution(String),

    #[error("存储错误: {0}")]
    Storage(String),

    #[error("插件错误: {0}")]
    Plugin(String),

    #[error("AI 提供者错误: {0}")]
    AiProvider(String),

    #[error("配置错误: {0}")]
    Config(String),

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

    #[error("序列化错误: {0}")]
    Serialization(#[from] serde_json::Error),
}

/// 统一 Result 别名
pub type Result<T> = std::result::Result<T, Error>;
