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

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


class CreateKeyInterval(str, Enum):
    r"""Unkey will automatically refill verifications at the set interval."""

    DAILY = "daily"
    MONTHLY = "monthly"


class CreateKeyRefillTypedDict(TypedDict):
    r"""Unkey enables you to refill verifications for each key at regular intervals."""

    interval: CreateKeyInterval
    r"""Unkey will automatically refill verifications at the set interval."""
    amount: int
    r"""The number of verifications to refill for each occurrence is determined individually for each key."""
    refill_day: NotRequired[float]
    r"""The day of the month, when we will refill the remaining verifications. To refill on the 15th of each month, set 'refillDay': 15.
    If the day does not exist, for example you specified the 30th and it's february, we will refill them on the last day of the month instead.
    """


class CreateKeyRefill(BaseModel):
    r"""Unkey enables you to refill verifications for each key at regular intervals."""

    interval: CreateKeyInterval
    r"""Unkey will automatically refill verifications at the set interval."""

    amount: int
    r"""The number of verifications to refill for each occurrence is determined individually for each key."""

    refill_day: Annotated[Optional[float], pydantic.Field(alias="refillDay")] = None
    r"""The day of the month, when we will refill the remaining verifications. To refill on the 15th of each month, set 'refillDay': 15.
    If the day does not exist, for example you specified the 30th and it's february, we will refill them on the last day of the month instead.
    """


@deprecated(
    "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
)
class CreateKeyType(str, Enum):
    r"""Deprecated, use `async`. Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate.
    https://unkey.dev/docs/features/ratelimiting - Learn more
    """

    FAST = "fast"
    CONSISTENT = "consistent"


class CreateKeyRatelimitTypedDict(TypedDict):
    r"""Unkey comes with per-key fixed-window ratelimiting out of the box."""

    limit: int
    r"""The total amount of requests in a given interval."""
    async_: NotRequired[bool]
    r"""Async will return a response immediately, lowering latency at the cost of accuracy. Will be required soon.
    https://unkey.dev/docs/features/ratelimiting - Learn more
    """
    type: NotRequired[CreateKeyType]
    r"""Deprecated, use `async`. Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate.
    https://unkey.dev/docs/features/ratelimiting - Learn more
    """
    duration: NotRequired[int]
    r"""The window duration in milliseconds. Will be required soon."""
    refill_rate: NotRequired[int]
    r"""How many tokens to refill during each refillInterval."""
    refill_interval: NotRequired[int]
    r"""The refill timeframe, in milliseconds."""


class CreateKeyRatelimit(BaseModel):
    r"""Unkey comes with per-key fixed-window ratelimiting out of the box."""

    limit: int
    r"""The total amount of requests in a given interval."""

    async_: Annotated[Optional[bool], pydantic.Field(alias="async")] = True
    r"""Async will return a response immediately, lowering latency at the cost of accuracy. Will be required soon.
    https://unkey.dev/docs/features/ratelimiting - Learn more
    """

    type: Annotated[
        Optional[CreateKeyType],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
        ),
    ] = CreateKeyType.FAST
    r"""Deprecated, use `async`. Fast ratelimiting doesn't add latency, while consistent ratelimiting is more accurate.
    https://unkey.dev/docs/features/ratelimiting - Learn more
    """

    duration: Optional[int] = None
    r"""The window duration in milliseconds. Will be required soon."""

    refill_rate: Annotated[
        Optional[int],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible.",
            alias="refillRate",
        ),
    ] = None
    r"""How many tokens to refill during each refillInterval."""

    refill_interval: Annotated[
        Optional[int],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible.",
            alias="refillInterval",
        ),
    ] = None
    r"""The refill timeframe, in milliseconds."""


class CreateKeyRequestBodyTypedDict(TypedDict):
    api_id: str
    r"""Choose an `API` where this key should be created."""
    prefix: NotRequired[str]
    r"""To make it easier for your users to understand which product an api key belongs to, you can add prefix them.

    For example Stripe famously prefixes their customer ids with cus_ or their api keys with sk_live_.

    The underscore is automatically added if you are defining a prefix, for example: \"prefix\": \"abc\" will result in a key like abc_xxxxxxxxx

    """
    name: NotRequired[str]
    r"""The name for your Key. This is not customer facing."""
    byte_length: NotRequired[int]
    r"""The byte length used to generate your key determines its entropy as well as its length. Higher is better, but keys become longer and more annoying to handle. The default is 16 bytes, or 2^^128 possible combinations."""
    owner_id: NotRequired[str]
    r"""Deprecated, use `externalId`"""
    external_id: NotRequired[str]
    r"""Your user's Id. This will provide a link between Unkey and your customer record.
    When validating a key, we will return this back to you, so you can clearly identify your user from their api key.
    """
    meta: NotRequired[Dict[str, Nullable[Any]]]
    r"""This is a place for dynamic meta data, anything that feels useful for you should go here"""
    roles: NotRequired[List[str]]
    r"""A list of roles that this key should have. If the role does not exist, an error is thrown"""
    permissions: NotRequired[List[str]]
    r"""A list of permissions that this key should have. If the permission does not exist, an error is thrown"""
    expires: NotRequired[int]
    r"""You can auto expire keys by providing a unix timestamp in milliseconds. Once Keys expire they will automatically be disabled and are no longer valid unless you enable them again."""
    remaining: NotRequired[int]
    r"""You can limit the number of requests a key can make. Once a key reaches 0 remaining requests, it will automatically be disabled and is no longer valid unless you update it.
    https://unkey.dev/docs/features/remaining - Learn more
    """
    refill: NotRequired[CreateKeyRefillTypedDict]
    r"""Unkey enables you to refill verifications for each key at regular intervals."""
    ratelimit: NotRequired[CreateKeyRatelimitTypedDict]
    r"""Unkey comes with per-key fixed-window ratelimiting out of the box."""
    enabled: NotRequired[bool]
    r"""Sets if key is enabled or disabled. Disabled keys are not valid."""
    recoverable: NotRequired[bool]
    r"""You may want to show keys again later. While we do not recommend this, we leave this option open for you.

    In addition to storing the key's hash, recoverable keys are stored in an encrypted vault, allowing you to retrieve and display the plaintext later.

    [https://www.unkey.com/docs/security/recovering-keys](https://www.unkey.com/docs/security/recovering-keys) for more information.
    """
    environment: NotRequired[str]
    r"""Environments allow you to divide your keyspace.

    Some applications like Stripe, Clerk, WorkOS and others have a concept of \"live\" and \"test\" keys to
    give the developer a way to develop their own application without the risk of modifying real world
    resources.

    When you set an environment, we will return it back to you when validating the key, so you can
    handle it correctly.

    """


class CreateKeyRequestBody(BaseModel):
    api_id: Annotated[str, pydantic.Field(alias="apiId")]
    r"""Choose an `API` where this key should be created."""

    prefix: Optional[str] = None
    r"""To make it easier for your users to understand which product an api key belongs to, you can add prefix them.

    For example Stripe famously prefixes their customer ids with cus_ or their api keys with sk_live_.

    The underscore is automatically added if you are defining a prefix, for example: \"prefix\": \"abc\" will result in a key like abc_xxxxxxxxx

    """

    name: Optional[str] = None
    r"""The name for your Key. This is not customer facing."""

    byte_length: Annotated[Optional[int], pydantic.Field(alias="byteLength")] = 16
    r"""The byte length used to generate your key determines its entropy as well as its length. Higher is better, but keys become longer and more annoying to handle. The default is 16 bytes, or 2^^128 possible combinations."""

    owner_id: Annotated[
        Optional[str],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible.",
            alias="ownerId",
        ),
    ] = None
    r"""Deprecated, use `externalId`"""

    external_id: Annotated[Optional[str], pydantic.Field(alias="externalId")] = None
    r"""Your user's Id. This will provide a link between Unkey and your customer record.
    When validating a key, we will return this back to you, so you can clearly identify your user from their api key.
    """

    meta: Optional[Dict[str, Nullable[Any]]] = None
    r"""This is a place for dynamic meta data, anything that feels useful for you should go here"""

    roles: Optional[List[str]] = None
    r"""A list of roles that this key should have. If the role does not exist, an error is thrown"""

    permissions: Optional[List[str]] = None
    r"""A list of permissions that this key should have. If the permission does not exist, an error is thrown"""

    expires: Optional[int] = None
    r"""You can auto expire keys by providing a unix timestamp in milliseconds. Once Keys expire they will automatically be disabled and are no longer valid unless you enable them again."""

    remaining: Optional[int] = None
    r"""You can limit the number of requests a key can make. Once a key reaches 0 remaining requests, it will automatically be disabled and is no longer valid unless you update it.
    https://unkey.dev/docs/features/remaining - Learn more
    """

    refill: Optional[CreateKeyRefill] = None
    r"""Unkey enables you to refill verifications for each key at regular intervals."""

    ratelimit: Optional[CreateKeyRatelimit] = None
    r"""Unkey comes with per-key fixed-window ratelimiting out of the box."""

    enabled: Optional[bool] = True
    r"""Sets if key is enabled or disabled. Disabled keys are not valid."""

    recoverable: Optional[bool] = False
    r"""You may want to show keys again later. While we do not recommend this, we leave this option open for you.

    In addition to storing the key's hash, recoverable keys are stored in an encrypted vault, allowing you to retrieve and display the plaintext later.

    [https://www.unkey.com/docs/security/recovering-keys](https://www.unkey.com/docs/security/recovering-keys) for more information.
    """

    environment: Optional[str] = None
    r"""Environments allow you to divide your keyspace.

    Some applications like Stripe, Clerk, WorkOS and others have a concept of \"live\" and \"test\" keys to
    give the developer a way to develop their own application without the risk of modifying real world
    resources.

    When you set an environment, we will return it back to you when validating the key, so you can
    handle it correctly.

    """


class CreateKeyResponseBodyTypedDict(TypedDict):
    r"""The configuration for an api"""

    key_id: str
    r"""The id of the key. This is not a secret and can be stored as a reference if you wish. You need the keyId to update or delete a key later."""
    key: str
    r"""The newly created api key, do not store this on your own system but pass it along to your user."""


class CreateKeyResponseBody(BaseModel):
    r"""The configuration for an api"""

    key_id: Annotated[str, pydantic.Field(alias="keyId")]
    r"""The id of the key. This is not a secret and can be stored as a reference if you wish. You need the keyId to update or delete a key later."""

    key: str
    r"""The newly created api key, do not store this on your own system but pass it along to your user."""


class CreateKeyResponseTypedDict(TypedDict):
    http_meta: HTTPMetadataTypedDict
    object: NotRequired[CreateKeyResponseBodyTypedDict]
    r"""The configuration for an api"""


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

    object: Optional[CreateKeyResponseBody] = None
    r"""The configuration for an api"""
