"""Custom exceptions for the Contiss SDK."""

from typing import Any, Dict, Optional


class ContissError(Exception):
    """Base exception for all Contiss SDK errors."""

    def __init__(self, message: str) -> None:
        """Initialize the error.

        Args:
            message: Error message
        """
        self.message = message
        super().__init__(self.message)


class AuthenticationError(ContissError):
    """Raised when authentication fails."""

    pass


class ValidationError(ContissError):
    """Raised when request validation fails."""

    pass


class NotFoundError(ContissError):
    """Raised when a resource is not found."""

    pass


class ConflictError(ContissError):
    """Raised when there's a conflict (e.g., resource already exists)."""

    pass


class RateLimitError(ContissError):
    """Raised when rate limit is exceeded."""

    def __init__(self, message: str, retry_after: Optional[int] = None) -> None:
        """Initialize the error.

        Args:
            message: Error message
            retry_after: Number of seconds to wait before retrying
        """
        super().__init__(message)
        self.retry_after = retry_after


class APIError(ContissError):
    """Raised for generic API errors."""

    def __init__(
        self, message: str, status_code: int, response: Optional[Dict[str, Any]] = None
    ) -> None:
        """Initialize the error.

        Args:
            message: Error message
            status_code: HTTP status code
            response: Full response data from the API
        """
        super().__init__(message)
        self.status_code = status_code
        self.response = response or {}


class TimeoutError(ContissError):
    """Raised when a request times out."""

    pass


class ConnectionError(ContissError):
    """Raised when connection to the API fails."""

    pass
