# coding: utf-8

"""
Perigon API

The Perigon API provides access to comprehensive news and web content data. To use the API, simply sign up for a Perigon Business Solutions account to obtain your API key. Your available features may vary based on your plan. See the Authentication section for details on how to use your API key.

The version of the OpenAPI document: 1.0.0
Contact: data@perigon.io
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing_extensions import Self

from perigon.models.auth_exception_cause import AuthExceptionCause
from perigon.models.auth_exception_cause_stack_trace_inner import (
    AuthExceptionCauseStackTraceInner,
)
from perigon.models.auth_exception_suppressed_inner import AuthExceptionSuppressedInner


class TooManyRequestsException(BaseModel):
    """
    TooManyRequestsException
    """  # noqa: E501

    cause: Optional[AuthExceptionCause] = None
    stack_trace: Optional[List[AuthExceptionCauseStackTraceInner]] = Field(
        default=None, alias="stackTrace"
    )
    status: Optional[StrictStr] = None
    message: Optional[StrictStr] = None
    suppressed: Optional[List[AuthExceptionSuppressedInner]] = None
    localized_message: Optional[StrictStr] = Field(
        default=None, alias="localizedMessage"
    )
    __properties: ClassVar[List[str]] = [
        "cause",
        "stackTrace",
        "status",
        "message",
        "suppressed",
        "localizedMessage",
    ]

    @field_validator("status")
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(
            [
                "100 CONTINUE",
                "101 SWITCHING_PROTOCOLS",
                "102 PROCESSING",
                "103 CHECKPOINT",
                "200 OK",
                "201 CREATED",
                "202 ACCEPTED",
                "203 NON_AUTHORITATIVE_INFORMATION",
                "204 NO_CONTENT",
                "205 RESET_CONTENT",
                "206 PARTIAL_CONTENT",
                "207 MULTI_STATUS",
                "208 ALREADY_REPORTED",
                "226 IM_USED",
                "300 MULTIPLE_CHOICES",
                "301 MOVED_PERMANENTLY",
                "302 FOUND",
                "302 MOVED_TEMPORARILY",
                "303 SEE_OTHER",
                "304 NOT_MODIFIED",
                "305 USE_PROXY",
                "307 TEMPORARY_REDIRECT",
                "308 PERMANENT_REDIRECT",
                "400 BAD_REQUEST",
                "401 UNAUTHORIZED",
                "402 PAYMENT_REQUIRED",
                "403 FORBIDDEN",
                "404 NOT_FOUND",
                "405 METHOD_NOT_ALLOWED",
                "406 NOT_ACCEPTABLE",
                "407 PROXY_AUTHENTICATION_REQUIRED",
                "408 REQUEST_TIMEOUT",
                "409 CONFLICT",
                "410 GONE",
                "411 LENGTH_REQUIRED",
                "412 PRECONDITION_FAILED",
                "413 PAYLOAD_TOO_LARGE",
                "413 REQUEST_ENTITY_TOO_LARGE",
                "414 URI_TOO_LONG",
                "414 REQUEST_URI_TOO_LONG",
                "415 UNSUPPORTED_MEDIA_TYPE",
                "416 REQUESTED_RANGE_NOT_SATISFIABLE",
                "417 EXPECTATION_FAILED",
                "418 I_AM_A_TEAPOT",
                "419 INSUFFICIENT_SPACE_ON_RESOURCE",
                "420 METHOD_FAILURE",
                "421 DESTINATION_LOCKED",
                "422 UNPROCESSABLE_ENTITY",
                "423 LOCKED",
                "424 FAILED_DEPENDENCY",
                "425 TOO_EARLY",
                "426 UPGRADE_REQUIRED",
                "428 PRECONDITION_REQUIRED",
                "429 TOO_MANY_REQUESTS",
                "431 REQUEST_HEADER_FIELDS_TOO_LARGE",
                "451 UNAVAILABLE_FOR_LEGAL_REASONS",
                "500 INTERNAL_SERVER_ERROR",
                "501 NOT_IMPLEMENTED",
                "502 BAD_GATEWAY",
                "503 SERVICE_UNAVAILABLE",
                "504 GATEWAY_TIMEOUT",
                "505 HTTP_VERSION_NOT_SUPPORTED",
                "506 VARIANT_ALSO_NEGOTIATES",
                "507 INSUFFICIENT_STORAGE",
                "508 LOOP_DETECTED",
                "509 BANDWIDTH_LIMIT_EXCEEDED",
                "510 NOT_EXTENDED",
                "511 NETWORK_AUTHENTICATION_REQUIRED",
            ]
        ):
            raise ValueError(
                "must be one of enum values ('100 CONTINUE', '101 SWITCHING_PROTOCOLS', '102 PROCESSING', '103 CHECKPOINT', '200 OK', '201 CREATED', '202 ACCEPTED', '203 NON_AUTHORITATIVE_INFORMATION', '204 NO_CONTENT', '205 RESET_CONTENT', '206 PARTIAL_CONTENT', '207 MULTI_STATUS', '208 ALREADY_REPORTED', '226 IM_USED', '300 MULTIPLE_CHOICES', '301 MOVED_PERMANENTLY', '302 FOUND', '302 MOVED_TEMPORARILY', '303 SEE_OTHER', '304 NOT_MODIFIED', '305 USE_PROXY', '307 TEMPORARY_REDIRECT', '308 PERMANENT_REDIRECT', '400 BAD_REQUEST', '401 UNAUTHORIZED', '402 PAYMENT_REQUIRED', '403 FORBIDDEN', '404 NOT_FOUND', '405 METHOD_NOT_ALLOWED', '406 NOT_ACCEPTABLE', '407 PROXY_AUTHENTICATION_REQUIRED', '408 REQUEST_TIMEOUT', '409 CONFLICT', '410 GONE', '411 LENGTH_REQUIRED', '412 PRECONDITION_FAILED', '413 PAYLOAD_TOO_LARGE', '413 REQUEST_ENTITY_TOO_LARGE', '414 URI_TOO_LONG', '414 REQUEST_URI_TOO_LONG', '415 UNSUPPORTED_MEDIA_TYPE', '416 REQUESTED_RANGE_NOT_SATISFIABLE', '417 EXPECTATION_FAILED', '418 I_AM_A_TEAPOT', '419 INSUFFICIENT_SPACE_ON_RESOURCE', '420 METHOD_FAILURE', '421 DESTINATION_LOCKED', '422 UNPROCESSABLE_ENTITY', '423 LOCKED', '424 FAILED_DEPENDENCY', '425 TOO_EARLY', '426 UPGRADE_REQUIRED', '428 PRECONDITION_REQUIRED', '429 TOO_MANY_REQUESTS', '431 REQUEST_HEADER_FIELDS_TOO_LARGE', '451 UNAVAILABLE_FOR_LEGAL_REASONS', '500 INTERNAL_SERVER_ERROR', '501 NOT_IMPLEMENTED', '502 BAD_GATEWAY', '503 SERVICE_UNAVAILABLE', '504 GATEWAY_TIMEOUT', '505 HTTP_VERSION_NOT_SUPPORTED', '506 VARIANT_ALSO_NEGOTIATES', '507 INSUFFICIENT_STORAGE', '508 LOOP_DETECTED', '509 BANDWIDTH_LIMIT_EXCEEDED', '510 NOT_EXTENDED', '511 NETWORK_AUTHENTICATION_REQUIRED')"
            )
        return value

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of TooManyRequestsException from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of cause
        if self.cause:
            _dict["cause"] = self.cause.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in stack_trace (list)
        _items = []
        if self.stack_trace:
            for _item_stack_trace in self.stack_trace:
                if _item_stack_trace:
                    _items.append(_item_stack_trace.to_dict())
            _dict["stackTrace"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in suppressed (list)
        _items = []
        if self.suppressed:
            for _item_suppressed in self.suppressed:
                if _item_suppressed:
                    _items.append(_item_suppressed.to_dict())
            _dict["suppressed"] = _items
        # set to None if cause (nullable) is None
        # and model_fields_set contains the field
        if self.cause is None and "cause" in self.model_fields_set:
            _dict["cause"] = None

        # set to None if stack_trace (nullable) is None
        # and model_fields_set contains the field
        if self.stack_trace is None and "stack_trace" in self.model_fields_set:
            _dict["stackTrace"] = None

        # set to None if status (nullable) is None
        # and model_fields_set contains the field
        if self.status is None and "status" in self.model_fields_set:
            _dict["status"] = None

        # set to None if message (nullable) is None
        # and model_fields_set contains the field
        if self.message is None and "message" in self.model_fields_set:
            _dict["message"] = None

        # set to None if suppressed (nullable) is None
        # and model_fields_set contains the field
        if self.suppressed is None and "suppressed" in self.model_fields_set:
            _dict["suppressed"] = None

        # set to None if localized_message (nullable) is None
        # and model_fields_set contains the field
        if (
            self.localized_message is None
            and "localized_message" in self.model_fields_set
        ):
            _dict["localizedMessage"] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of TooManyRequestsException from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate(
            {
                "cause": (
                    AuthExceptionCause.from_dict(obj["cause"])
                    if obj.get("cause") is not None
                    else None
                ),
                "stackTrace": (
                    [
                        AuthExceptionCauseStackTraceInner.from_dict(_item)
                        for _item in obj["stackTrace"]
                    ]
                    if obj.get("stackTrace") is not None
                    else None
                ),
                "status": obj.get("status"),
                "message": obj.get("message"),
                "suppressed": (
                    [
                        AuthExceptionSuppressedInner.from_dict(_item)
                        for _item in obj["suppressed"]
                    ]
                    if obj.get("suppressed") is not None
                    else None
                ),
                "localizedMessage": obj.get("localizedMessage"),
            }
        )
        return _obj
