"""AI 模块异常层级。

所有 DashScope 相关异常继承自 DashScopeError 基类，
便于上层统一捕获和分类处理。
"""

from __future__ import annotations


class DashScopeError(Exception):
    """DashScope 异常基类。"""


class DashScopeApiError(DashScopeError):
    """Application API 调用失败（重试耗尽后）。"""

    def __init__(self, message: str, status_code: int | None = None):
        super().__init__(message)
        self.status_code = status_code


class DashScopeAuthError(DashScopeApiError):
    """API Key 无效（HTTP 401）。"""

    def __init__(self, message: str = "API Key 无效或已过期"):
        super().__init__(message, status_code=401)


class DashScopeTimeoutError(DashScopeApiError):
    """调用超时。"""

    def __init__(self, message: str = "DashScope API 调用超时"):
        super().__init__(message, status_code=None)


class DashScopeJsonParseError(DashScopeError):
    """响应 JSON 解析失败（重试耗尽后）。"""

    def __init__(self, message: str, raw_content: str = ""):
        super().__init__(message)
        self.raw_content = raw_content


class CircuitOpenError(DashScopeError):
    """熔断器处于 OPEN 状态，拒绝请求。"""


class RateLimitExceededError(DashScopeError):
    """限流阈值超限。"""


class BudgetExceededError(DashScopeError):
    """Token 预算超限。"""
