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

from __future__ import annotations
from .httpmetadata import HTTPMetadata, HTTPMetadataTypedDict
import pydantic
from typing import Any, Dict, List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict
from unkey_py.types import BaseModel, Nullable


class UpdateIdentityRatelimitsTypedDict(TypedDict):
    name: str
    r"""The name of this limit. You will need to use this again when verifying a key."""
    limit: int
    r"""How many requests may pass within a given window before requests are rejected."""
    duration: int
    r"""The duration for each ratelimit window in milliseconds."""


class UpdateIdentityRatelimits(BaseModel):
    name: str
    r"""The name of this limit. You will need to use this again when verifying a key."""

    limit: int
    r"""How many requests may pass within a given window before requests are rejected."""

    duration: int
    r"""The duration for each ratelimit window in milliseconds."""


class UpdateIdentityRequestBodyTypedDict(TypedDict):
    identity_id: NotRequired[str]
    r"""The id of the identity to update, use either `identityId` or `externalId`, if both are provided, `identityId` takes precedence."""
    external_id: NotRequired[str]
    r"""The externalId of the identity to update, use either `identityId` or `externalId`, if both are provided, `identityId` takes precedence."""
    environment: NotRequired[str]
    r"""This is not yet used but here for future compatibility."""
    meta: NotRequired[Dict[str, Nullable[Any]]]
    r"""Attach metadata to this identity that you need to have access to when verifying a key.

    Set to `{}` to clear.

    This will be returned as part of the `verifyKey` response.

    """
    ratelimits: NotRequired[List[UpdateIdentityRatelimitsTypedDict]]
    r"""Attach ratelimits to this identity.

    This overwrites all existing ratelimits on this identity.
    Setting an empty array will delete all existing ratelimits.

    When verifying keys, you can specify which limits you want to use and all keys attached to this identity, will share the limits.
    """


class UpdateIdentityRequestBody(BaseModel):
    identity_id: Annotated[Optional[str], pydantic.Field(alias="identityId")] = None
    r"""The id of the identity to update, use either `identityId` or `externalId`, if both are provided, `identityId` takes precedence."""

    external_id: Annotated[Optional[str], pydantic.Field(alias="externalId")] = None
    r"""The externalId of the identity to update, use either `identityId` or `externalId`, if both are provided, `identityId` takes precedence."""

    environment: Optional[str] = "default"
    r"""This is not yet used but here for future compatibility."""

    meta: Optional[Dict[str, Nullable[Any]]] = None
    r"""Attach metadata to this identity that you need to have access to when verifying a key.

    Set to `{}` to clear.

    This will be returned as part of the `verifyKey` response.

    """

    ratelimits: Optional[List[UpdateIdentityRatelimits]] = None
    r"""Attach ratelimits to this identity.

    This overwrites all existing ratelimits on this identity.
    Setting an empty array will delete all existing ratelimits.

    When verifying keys, you can specify which limits you want to use and all keys attached to this identity, will share the limits.
    """


class UpdateIdentityIdentitiesRatelimitsTypedDict(TypedDict):
    name: str
    r"""The name of this limit."""
    limit: int
    r"""How many requests may pass within a given window before requests are rejected."""
    duration: int
    r"""The duration for each ratelimit window in milliseconds."""


class UpdateIdentityIdentitiesRatelimits(BaseModel):
    name: str
    r"""The name of this limit."""

    limit: int
    r"""How many requests may pass within a given window before requests are rejected."""

    duration: int
    r"""The duration for each ratelimit window in milliseconds."""


class UpdateIdentityResponseBodyTypedDict(TypedDict):
    r"""The identity after the update."""

    id: str
    r"""The id of the identity."""
    external_id: str
    r"""The externalId of the identity."""
    meta: Dict[str, Nullable[Any]]
    r"""The metadata attached to this identity."""
    ratelimits: List[UpdateIdentityIdentitiesRatelimitsTypedDict]


class UpdateIdentityResponseBody(BaseModel):
    r"""The identity after the update."""

    id: str
    r"""The id of the identity."""

    external_id: Annotated[str, pydantic.Field(alias="externalId")]
    r"""The externalId of the identity."""

    meta: Dict[str, Nullable[Any]]
    r"""The metadata attached to this identity."""

    ratelimits: List[UpdateIdentityIdentitiesRatelimits]


class UpdateIdentityResponseTypedDict(TypedDict):
    http_meta: HTTPMetadataTypedDict
    object: NotRequired[UpdateIdentityResponseBodyTypedDict]
    r"""The identity after the update."""


class UpdateIdentityResponse(BaseModel):
    http_meta: Annotated[Optional[HTTPMetadata], pydantic.Field(exclude=True)] = None

    object: Optional[UpdateIdentityResponseBody] = None
    r"""The identity after the update."""
