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


class ConfigCreateParams(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

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


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


Origin: TypeAlias = Union[OriginPublicDatabase, OriginAccessProtectedDatabaseBehindCloudflareTunnel]


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