"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from dataclasses import dataclass, field
import httpx
from typing import Optional
from unkey.py.errors import UnkeyError
from unkey.py.models import baseerror as models_baseerror, meta as models_meta
from unkey.py.types import BaseModel


class TooManyRequestsErrorResponseData(BaseModel):
    meta: models_meta.Meta
    r"""Metadata object included in every API response. This provides context about the request and is essential for debugging, audit trails, and support inquiries. The `requestId` is particularly important when troubleshooting issues with the Unkey support team."""

    error: models_baseerror.BaseError
    r"""Base error structure following Problem Details for HTTP APIs (RFC 7807). This provides a standardized way to carry machine-readable details of errors in HTTP response content."""


@dataclass(unsafe_hash=True)
class TooManyRequestsErrorResponse(UnkeyError):
    r"""Error response when the client has sent too many requests in a given time period. This occurs when you've exceeded a rate limit or quota for the resource you're accessing.

    The rate limit resets automatically after the time window expires. To avoid this error:
    - Implement exponential backoff when retrying requests
    - Cache results where appropriate to reduce request frequency
    - Check the error detail message for specific quota information
    - Contact support if you need a higher quota for your use case
    """

    data: TooManyRequestsErrorResponseData = field(hash=False)

    def __init__(
        self,
        data: TooManyRequestsErrorResponseData,
        raw_response: httpx.Response,
        body: Optional[str] = None,
    ):
        message = body or raw_response.text
        super().__init__(message, raw_response, body)
        object.__setattr__(self, "data", data)
