"""Pixwell SDK exceptions."""

from typing import Optional


class PixwellError(Exception):
    """Base exception for Pixwell SDK errors."""

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

    def __str__(self) -> str:
        return self.message


class AuthenticationError(PixwellError):
    """Authentication error (invalid or missing API key)."""

    def __init__(self, message: str = "Invalid or missing API key") -> None:
        super().__init__(message, "AUTHENTICATION_ERROR", 401)


class RateLimitError(PixwellError):
    """Rate limit exceeded error."""

    def __init__(
        self,
        message: str = "Rate limit exceeded",
        retry_after: Optional[int] = None,
    ) -> None:
        super().__init__(message, "RATE_LIMIT_ERROR", 429)
        self.retry_after = retry_after


class ValidationError(PixwellError):
    """Validation error for invalid parameters."""

    def __init__(self, message: str, field: Optional[str] = None) -> None:
        super().__init__(message, "VALIDATION_ERROR", 400)
        self.field = field


class CaptureError(PixwellError):
    """Screenshot capture error."""

    def __init__(self, message: str) -> None:
        super().__init__(message, "CAPTURE_ERROR", 500)


class NetworkError(PixwellError):
    """Network or timeout error."""

    def __init__(self, message: str = "Network request failed") -> None:
        super().__init__(message, "NETWORK_ERROR")
