# src/ihyee/exceptions.py
"""Exception hierarchy for ihyee SDK."""
from __future__ import annotations

from typing import Optional


class IhyeeError(Exception):
    """Base exception for all ihyee API errors."""

    def __init__(self, code: str, message: str, status_code: int) -> None:
        self.code = code
        self.message = message
        self.status_code = status_code
        super().__init__(f"{code}: {message}")


class AuthError(IhyeeError):
    """Raised on 401 (invalid/missing key) or 403 (key disabled)."""

    pass


class RateLimitError(IhyeeError):
    """Raised on 429. Includes retry_after_seconds if provided by the API."""

    def __init__(
        self, code: str, message: str, retry_after: Optional[int] = None
    ) -> None:
        self.retry_after = retry_after
        super().__init__(code, message, 429)


class BadRequestError(IhyeeError):
    """Raised on 400 (validation error, invalid parameters)."""

    pass


class ServerError(IhyeeError):
    """Raised on 502 (upstream fetch failed), 504 (render timeout), or other 5xx."""

    pass
