import httpx


class AbuseIPDBError(Exception):
    """Base error for all errors raised by this SDK."""


class InvalidParameterError(AbuseIPDBError, ValueError):
    """A client argument violates AbuseIPDB parameter constraints."""


class MissingAPIKeyError(AbuseIPDBError):
    """No explicit or environment API key was supplied."""


class AbuseIPDBAPIError(AbuseIPDBError):
    """An AbuseIPDB HTTP response indicates failure."""

    def __init__(
        self,
        message: str,
        *,
        response: httpx.Response,
        detail: str | None = None,
    ) -> None:
        super().__init__(message)
        self.response = response
        self.status_code = response.status_code
        self.detail = detail


class PaymentRequiredError(AbuseIPDBAPIError):
    """HTTP 402: account plan does not include requested feature."""


class TooManyRequestsError(AbuseIPDBAPIError):
    """HTTP 429: endpoint rate limit was exceeded."""


class UnprocessableContentError(AbuseIPDBAPIError):
    """HTTP 422: API could not process request parameters."""


class UnconventionalAPIError(AbuseIPDBAPIError):
    """Any unsuccessful status not mapped to a specialized API error."""


# Recognizable aliases for developers porting existing Laravel code.
InvalidParameterException = InvalidParameterError
MissingAPIKeyException = MissingAPIKeyError
PaymentRequiredException = PaymentRequiredError
TooManyRequestsException = TooManyRequestsError
UnprocessableContentException = UnprocessableContentError
UnconventionalErrorException = UnconventionalAPIError
