# 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__ = [
    "ConfigUpdateParams",
    "Origin",
    "OriginPublicDatabase",
    "OriginAccessProtectedDatabaseBehindCloudflareTunnel",
    "OriginDatabaseReachableThroughAWorkersVPC",
    "Caching",
    "CachingHyperdriveHyperdriveCachingCommon",
    "CachingHyperdriveHyperdriveCachingEnabled",
    "MTLS",
]


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

    name: Required[str]
    """The name of the Hyperdrive configuration.

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

    origin: Required[Origin]

    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.
    """

    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 OriginPublicDatabase(TypedDict, total=False):
    database: Required[str]
    """Set the name of your origin database."""

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

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

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

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

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

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

    user: Required[str]
    """Set the user of your origin database."""


class OriginAccessProtectedDatabaseBehindCloudflareTunnel(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.
    """

    database: Required[str]
    """Set the name of your origin database."""

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

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

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

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

    user: Required[str]
    """Set the user of your origin database."""


class OriginDatabaseReachableThroughAWorkersVPC(TypedDict, total=False):
    database: Required[str]
    """Set the name of your origin database."""

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

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

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

    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.
    """

    user: Required[str]
    """Set the user of your origin database."""


Origin: TypeAlias = Union[
    OriginPublicDatabase, OriginAccessProtectedDatabaseBehindCloudflareTunnel, OriginDatabaseReachableThroughAWorkersVPC
]


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."""
