# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing import Union
from typing_extensions import Literal, Required, TypeAlias, TypedDict

__all__ = [
    "ConfigEditParams",
    "Caching",
    "CachingHyperdriveHyperdriveCachingCommon",
    "CachingHyperdriveHyperdriveCachingEnabled",
    "MTLS",
    "Origin",
    "OriginHyperdriveHyperdriveDatabase",
    "OriginHyperdriveInternetOrigin",
    "OriginHyperdriveOverAccessOrigin",
    "OriginHyperdriveVPCServiceOrigin",
]


class ConfigEditParams(TypedDict, total=False):
    account_id: Required[str]
    """Define configurations using a unique string identifier."""

    caching: Caching

    mtls: MTLS
    """mTLS configuration for the origin connection.

    Cannot be used with VPC Service origins; TLS must be managed on the VPC Service.
    """

    name: str
    """The name of the Hyperdrive configuration.

    Used to identify the configuration in the Cloudflare dashboard and API.
    """

    origin: Origin
    """Connect to a database through a Workers VPC Service.

    TLS settings (mTLS, sslmode) cannot be configured on the Hyperdrive when using a
    VPC Service origin; TLS must be managed on the VPC Service itself.
    """

    origin_connection_limit: int
    """
    The (soft) maximum number of connections the Hyperdrive is allowed to make to
    the origin database.

    Maximum allowed: 20 for free tier accounts, 100 for paid tier accounts. If not
    specified, defaults to 20 for free tier and 60 for paid tier. Contact Cloudflare
    if you need a higher limit.
    """


class CachingHyperdriveHyperdriveCachingCommon(TypedDict, total=False):
    disabled: bool
    """Set to true to disable caching of SQL responses. Default is false."""


class CachingHyperdriveHyperdriveCachingEnabled(TypedDict, total=False):
    disabled: bool
    """Set to true to disable caching of SQL responses. Default is false."""

    max_age: int
    """Specify the maximum duration (in seconds) items should persist in the cache.

    Defaults to 60 seconds if not specified.
    """

    stale_while_revalidate: int
    """Specify the number of seconds the cache may serve a stale response.

    Defaults to 15 seconds if not specified.
    """


Caching: TypeAlias = Union[CachingHyperdriveHyperdriveCachingCommon, CachingHyperdriveHyperdriveCachingEnabled]


class MTLS(TypedDict, total=False):
    """mTLS configuration for the origin connection.

    Cannot be used with VPC Service origins; TLS must be managed on the VPC Service.
    """

    ca_certificate_id: str
    """Define CA certificate ID obtained after uploading CA cert."""

    mtls_certificate_id: str
    """Define mTLS certificate ID obtained after uploading client cert."""

    sslmode: str
    """Set SSL mode to 'require', 'verify-ca', or 'verify-full' to verify the CA."""


class OriginHyperdriveHyperdriveDatabase(TypedDict, total=False):
    database: str
    """Set the name of your origin database."""

    password: str
    """Set the password needed to access your origin database.

    The API never returns this write-only value.
    """

    scheme: Literal["postgres", "postgresql", "mysql"]
    """Specifies the URL scheme used to connect to your origin database."""

    user: str
    """Set the user of your origin database."""


class OriginHyperdriveInternetOrigin(TypedDict, total=False):
    host: Required[str]
    """Defines the host (hostname or IP) of your origin database."""

    port: Required[int]
    """Defines the port of your origin database.

    Defaults to 5432 for PostgreSQL or 3306 for MySQL if not specified.
    """


class OriginHyperdriveOverAccessOrigin(TypedDict, total=False):
    access_client_id: Required[str]
    """
    Defines the Client ID of the Access token to use when connecting to the origin
    database.
    """

    access_client_secret: Required[str]
    """
    Defines the Client Secret of the Access Token to use when connecting to the
    origin database. The API never returns this write-only value.
    """

    host: Required[str]
    """Defines the host (hostname or IP) of your origin database."""


class OriginHyperdriveVPCServiceOrigin(TypedDict, total=False):
    """Connect to a database through a Workers VPC Service.

    TLS settings (mTLS, sslmode) cannot be configured on the Hyperdrive when using a VPC Service origin; TLS must be managed on the VPC Service itself.
    """

    service_id: Required[str]
    """The identifier of the Workers VPC Service to connect through.

    Hyperdrive will egress through the specified VPC Service to reach the origin
    database.
    """


Origin: TypeAlias = Union[
    OriginHyperdriveHyperdriveDatabase,
    OriginHyperdriveInternetOrigin,
    OriginHyperdriveOverAccessOrigin,
    OriginHyperdriveVPCServiceOrigin,
]
