"""Commune SDK exceptions."""

from __future__ import annotations

from typing import Optional


class CommuneError(Exception):
    """Base exception for all Commune SDK errors."""

    def __init__(self, message: str, status_code: Optional[int] = None):
        self.message = message
        self.status_code = status_code
        super().__init__(message)


class AuthenticationError(CommuneError):
    """Raised when authentication fails (401)."""

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


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

    def __init__(self, message: str = "Resource not found"):
        super().__init__(message, status_code=404)


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

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


class PermissionError(CommuneError):
    """Raised when the API key lacks required permissions (403)."""

    def __init__(self, message: str = "Insufficient permissions"):
        super().__init__(message, status_code=403)


class RateLimitError(CommuneError):
    """Raised when rate limits are exceeded (429)."""

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