//! 错误类型定义

use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
    #[error("认证失败: {0}")]
    AuthError(String),

    #[error("连接错误: {0}")]
    ConnectionError(String),

    #[error("协议错误: {0}")]
    ProtocolError(String),

    #[error("加密错误: {0}")]
    CryptoError(String),

    #[error("设备未找到: {0}")]
    DeviceNotFound(String),

    #[error("权限被拒绝: {0}")]
    PermissionDenied(String),

    #[error("会话过期")]
    SessionExpired,

    #[error("网络错误: {0}")]
    NetworkError(String),

    #[error("编码错误: {0}")]
    EncodingError(String),

    #[error("数据库错误: {0}")]
    DatabaseError(String),

    #[error("内部错误: {0}")]
    InternalError(String),

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

    #[error("序列化错误: {0}")]
    SerializationError(String),
}

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

impl From<serde_json::Error> for Error {
    fn from(e: serde_json::Error) -> Self {
        Error::SerializationError(e.to_string())
    }
}

impl From<bincode::Error> for Error {
    fn from(e: bincode::Error) -> Self {
        Error::SerializationError(e.to_string())
    }
}
