"""ZeliAI SDK 예외 클래스"""


class ZeliAIError(Exception):
    """ZeliAI API 기본 예외"""

    def __init__(self, message: str, status_code: int = None, error_type: str = None, error_code: str = None):
        self.message = message
        self.status_code = status_code
        self.error_type = error_type or "api_error"
        self.error_code = error_code
        super().__init__(self.message)

    def __str__(self):
        parts = [self.message]
        if self.status_code:
            parts.insert(0, f"[{self.status_code}]")
        if self.error_code:
            parts.append(f"(code: {self.error_code})")
        return " ".join(parts)


class AuthenticationError(ZeliAIError):
    """API 키 인증 실패"""

    def __init__(self, message: str = "Invalid or missing API key"):
        super().__init__(message, status_code=401, error_type="authentication_error")


class RateLimitError(ZeliAIError):
    """요청 한도 초과"""

    def __init__(self, message: str = "Rate limit exceeded"):
        super().__init__(message, status_code=429, error_type="rate_limit_error")


class ModelNotFoundError(ZeliAIError):
    """지원되지 않는 모델"""

    def __init__(self, model: str):
        super().__init__(
            f"Model '{model}' not found. Use client.models() to list available models.",
            status_code=404,
            error_type="invalid_request_error",
            error_code="model_not_found",
        )


class InvalidRequestError(ZeliAIError):
    """잘못된 요청"""

    def __init__(self, message: str = "Invalid request"):
        super().__init__(message, status_code=400, error_type="invalid_request_error")


class ServerError(ZeliAIError):
    """서버 내부 오류"""

    def __init__(self, message: str = "Internal server error"):
        super().__init__(message, status_code=500, error_type="server_error")
