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

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


class V1KeysVerifyKeyResponseRatelimitTypedDict(TypedDict):
    r"""The ratelimit configuration for this key. If this field is null or undefined, the key has no ratelimit."""

    limit: int
    r"""Maximum number of requests that can be made inside a window"""
    remaining: int
    r"""Remaining requests after this verification"""
    reset: int
    r"""Unix timestamp in milliseconds when the ratelimit will reset"""


class V1KeysVerifyKeyResponseRatelimit(BaseModel):
    r"""The ratelimit configuration for this key. If this field is null or undefined, the key has no ratelimit."""

    limit: int
    r"""Maximum number of requests that can be made inside a window"""

    remaining: int
    r"""Remaining requests after this verification"""

    reset: int
    r"""Unix timestamp in milliseconds when the ratelimit will reset"""


class Code(str, Enum):
    r"""A machine readable code why the key is not valid.
    Possible values are:
    - VALID: the key is valid and you should proceed
    - NOT_FOUND: the key does not exist or has expired
    - FORBIDDEN: the key is not allowed to access the api
    - USAGE_EXCEEDED: the key has exceeded its request limit
    - RATE_LIMITED: the key has been ratelimited
    - UNAUTHORIZED: the key is not authorized
    - DISABLED: the key is disabled
    - INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform this action
    - EXPIRED: The key was only valid for a certain time and has expired.

    These are validation codes, the HTTP status will be 200.

    """

    VALID = "VALID"
    NOT_FOUND = "NOT_FOUND"
    FORBIDDEN = "FORBIDDEN"
    USAGE_EXCEEDED = "USAGE_EXCEEDED"
    RATE_LIMITED = "RATE_LIMITED"
    UNAUTHORIZED = "UNAUTHORIZED"
    DISABLED = "DISABLED"
    INSUFFICIENT_PERMISSIONS = "INSUFFICIENT_PERMISSIONS"
    EXPIRED = "EXPIRED"


class V1KeysVerifyKeyResponseIdentityTypedDict(TypedDict):
    r"""The associated identity of this key."""

    id: str
    external_id: str
    meta: Dict[str, Nullable[Any]]


class V1KeysVerifyKeyResponseIdentity(BaseModel):
    r"""The associated identity of this key."""

    id: str

    external_id: Annotated[str, pydantic.Field(alias="externalId")]

    meta: Dict[str, Nullable[Any]]


class V1KeysVerifyKeyResponseTypedDict(TypedDict):
    valid: bool
    r"""Whether the key is valid or not.
    A key could be invalid for a number of reasons, for example if it has expired, has no more verifications left or if it has been deleted.
    """
    code: Code
    r"""A machine readable code why the key is not valid.
    Possible values are:
    - VALID: the key is valid and you should proceed
    - NOT_FOUND: the key does not exist or has expired
    - FORBIDDEN: the key is not allowed to access the api
    - USAGE_EXCEEDED: the key has exceeded its request limit
    - RATE_LIMITED: the key has been ratelimited
    - UNAUTHORIZED: the key is not authorized
    - DISABLED: the key is disabled
    - INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform this action
    - EXPIRED: The key was only valid for a certain time and has expired.

    These are validation codes, the HTTP status will be 200.

    """
    request_id: str
    r"""A unique id for this request, please provide it to Unkey support to help us debug your issue."""
    key_id: NotRequired[str]
    r"""The id of the key"""
    name: NotRequired[str]
    r"""The name of the key, give keys a name to easily identifiy their purpose"""
    owner_id: NotRequired[str]
    r"""The id of the tenant associated with this key. Use whatever reference you have in your system to identify the tenant. When verifying the key, we will send this field back to you, so you know who is accessing your API."""
    meta: NotRequired[Dict[str, Nullable[Any]]]
    r"""Any additional metadata you want to store with the key"""
    expires: NotRequired[int]
    r"""The unix timestamp in milliseconds when the key will expire. If this field is null or undefined, the key is not expiring."""
    ratelimit: NotRequired[V1KeysVerifyKeyResponseRatelimitTypedDict]
    r"""The ratelimit configuration for this key. If this field is null or undefined, the key has no ratelimit."""
    remaining: NotRequired[int]
    r"""The number of requests that can be made with this key before it becomes invalid. If this field is null or undefined, the key has no request limit."""
    enabled: NotRequired[bool]
    r"""Sets the key to be enabled or disabled. Disabled keys will not verify."""
    permissions: NotRequired[List[str]]
    r"""A list of all the permissions this key is connected to."""
    roles: NotRequired[List[str]]
    r"""A list of all the roles this key is connected to."""
    environment: NotRequired[str]
    r"""The environment of the key, this is what what you set when you crated the key"""
    identity: NotRequired[V1KeysVerifyKeyResponseIdentityTypedDict]
    r"""The associated identity of this key."""


class V1KeysVerifyKeyResponse(BaseModel):
    valid: bool
    r"""Whether the key is valid or not.
    A key could be invalid for a number of reasons, for example if it has expired, has no more verifications left or if it has been deleted.
    """

    code: Code
    r"""A machine readable code why the key is not valid.
    Possible values are:
    - VALID: the key is valid and you should proceed
    - NOT_FOUND: the key does not exist or has expired
    - FORBIDDEN: the key is not allowed to access the api
    - USAGE_EXCEEDED: the key has exceeded its request limit
    - RATE_LIMITED: the key has been ratelimited
    - UNAUTHORIZED: the key is not authorized
    - DISABLED: the key is disabled
    - INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform this action
    - EXPIRED: The key was only valid for a certain time and has expired.

    These are validation codes, the HTTP status will be 200.

    """

    request_id: Annotated[str, pydantic.Field(alias="requestId")]
    r"""A unique id for this request, please provide it to Unkey support to help us debug your issue."""

    key_id: Annotated[Optional[str], pydantic.Field(alias="keyId")] = None
    r"""The id of the key"""

    name: Optional[str] = None
    r"""The name of the key, give keys a name to easily identifiy their purpose"""

    owner_id: Annotated[Optional[str], pydantic.Field(alias="ownerId")] = None
    r"""The id of the tenant associated with this key. Use whatever reference you have in your system to identify the tenant. When verifying the key, we will send this field back to you, so you know who is accessing your API."""

    meta: Optional[Dict[str, Nullable[Any]]] = None
    r"""Any additional metadata you want to store with the key"""

    expires: Optional[int] = None
    r"""The unix timestamp in milliseconds when the key will expire. If this field is null or undefined, the key is not expiring."""

    ratelimit: Optional[V1KeysVerifyKeyResponseRatelimit] = None
    r"""The ratelimit configuration for this key. If this field is null or undefined, the key has no ratelimit."""

    remaining: Optional[int] = None
    r"""The number of requests that can be made with this key before it becomes invalid. If this field is null or undefined, the key has no request limit."""

    enabled: Optional[bool] = None
    r"""Sets the key to be enabled or disabled. Disabled keys will not verify."""

    permissions: Optional[List[str]] = None
    r"""A list of all the permissions this key is connected to."""

    roles: Optional[List[str]] = None
    r"""A list of all the roles this key is connected to."""

    environment: Optional[str] = None
    r"""The environment of the key, this is what what you set when you crated the key"""

    identity: Optional[V1KeysVerifyKeyResponseIdentity] = None
    r"""The associated identity of this key."""
