# -*- coding: utf-8 -*-
"""
统一异常处理模块
提供项目中所有自定义异常类
"""

from typing import Optional, Dict, Any


class V123PanError(Exception):
    """V123Pan 基类异常"""

    def __init__(self, message: str, code: Optional[int] = None, data: Optional[Dict[str, Any]] = None):
        self.message = message
        self.code = code
        self.data = data
        super().__init__(self.message)

    def __str__(self) -> str:
        if self.code is not None:
            return f"[{self.code}] {self.message}"
        return self.message


class APIError(V123PanError):
    """API 调用错误"""
    pass


class NetworkError(V123PanError):
    """网络错误"""
    pass


class AuthError(V123PanError):
    """认证错误"""
    pass


class RateLimitError(V123PanError):
    """QPS限流错误"""
    pass


class FileUploadError(V123PanError):
    """文件上传错误"""
    pass


class FileReadError(V123PanError):
    """文件读取错误"""
    pass


class HashComputationError(V123PanError):
    """哈希计算错误"""
    pass


class ResourceClosedError(V123PanError):
    """资源已关闭错误"""
    pass


class TimeoutError(V123PanError):
    """超时错误"""
    pass


class ValidationError(V123PanError):
    """参数验证错误"""
    pass


class SimpleFileSliceError(V123PanError):
    """SimpleFileSlice 基础异常"""
    pass


class CryptoError(V123PanError):
    """加密错误"""
    pass
