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

from __future__ import annotations
from .setapikeyquotaresponse import (
    SetAPIKeyQuotaResponse,
    SetAPIKeyQuotaResponseTypedDict,
)
from factify.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from factify.utils import FieldMetadata, PathParamMetadata, RequestMetadata
from pydantic import model_serializer
from typing import Dict, List
from typing_extensions import Annotated, NotRequired, TypedDict


class SetAPIKeyQuotaSetAPIKeyQuotaRequestTypedDict(TypedDict):
    r"""SetAPIKeyQuotaRequest creates or updates a per-key quota."""

    limit: NotRequired[Nullable[int]]
    r"""The limit for this key. Must be > 0."""
    organization_id: NotRequired[Nullable[str]]
    r"""Optional: organization ID. If not provided, uses the caller's organization."""


class SetAPIKeyQuotaSetAPIKeyQuotaRequest(BaseModel):
    r"""SetAPIKeyQuotaRequest creates or updates a per-key quota."""

    limit: OptionalNullable[int] = UNSET
    r"""The limit for this key. Must be > 0."""

    organization_id: OptionalNullable[str] = UNSET
    r"""Optional: organization ID. If not provided, uses the caller's organization."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["limit", "organization_id"])
        nullable_fields = set(["limit", "organization_id"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


class SetAPIKeyQuotaRequestTypedDict(TypedDict):
    api_key_id: str
    r"""The API key ID (required)."""
    body: SetAPIKeyQuotaSetAPIKeyQuotaRequestTypedDict


class SetAPIKeyQuotaRequest(BaseModel):
    api_key_id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""The API key ID (required)."""

    body: Annotated[
        SetAPIKeyQuotaSetAPIKeyQuotaRequest,
        FieldMetadata(request=RequestMetadata(media_type="application/json")),
    ]


class SetAPIKeyQuotaResponseResponseTypedDict(TypedDict):
    headers: Dict[str, List[str]]
    result: SetAPIKeyQuotaResponseTypedDict


class SetAPIKeyQuotaResponseResponse(BaseModel):
    headers: Dict[str, List[str]]

    result: SetAPIKeyQuotaResponse
