from typing import Optional, Any


class CPTError(Exception):
    """Base exception for CPT SDK errors."""

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

    def __str__(self) -> str:
        if self.status_code:
            return f"{self.message} (status: {self.status_code})"
        return self.message


class CPTAuthError(CPTError):
    """Raised when authentication fails."""

    def __init__(self, message: str = "Authentication failed"):
        super().__init__(message, status_code=401)


class CPTValidationError(CPTError):
    """Raised when validation fails."""

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


class CPTWebhookError(CPTError):
    """Raised when webhook verification fails."""

    def __init__(self, message: str = "Webhook verification failed"):
        super().__init__(message)
