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

from typing import Dict, List, Union, Optional
from datetime import datetime
from typing_extensions import Literal, Annotated, TypeAlias

from ..._utils import PropertyInfo
from ..._models import BaseModel
from .deployment import Deployment

__all__ = [
    "Project",
    "DeploymentConfigs",
    "DeploymentConfigsPreview",
    "DeploymentConfigsPreviewEnvVars",
    "DeploymentConfigsPreviewEnvVarsPagesPlainTextEnvVar",
    "DeploymentConfigsPreviewEnvVarsPagesSecretTextEnvVar",
    "DeploymentConfigsPreviewAIBindings",
    "DeploymentConfigsPreviewAnalyticsEngineDatasets",
    "DeploymentConfigsPreviewBrowsers",
    "DeploymentConfigsPreviewD1Databases",
    "DeploymentConfigsPreviewDurableObjectNamespaces",
    "DeploymentConfigsPreviewHyperdriveBindings",
    "DeploymentConfigsPreviewKVNamespaces",
    "DeploymentConfigsPreviewLimits",
    "DeploymentConfigsPreviewMTLSCertificates",
    "DeploymentConfigsPreviewPlacement",
    "DeploymentConfigsPreviewQueueProducers",
    "DeploymentConfigsPreviewR2Buckets",
    "DeploymentConfigsPreviewServices",
    "DeploymentConfigsPreviewVectorizeBindings",
    "DeploymentConfigsProduction",
    "DeploymentConfigsProductionEnvVars",
    "DeploymentConfigsProductionEnvVarsPagesPlainTextEnvVar",
    "DeploymentConfigsProductionEnvVarsPagesSecretTextEnvVar",
    "DeploymentConfigsProductionAIBindings",
    "DeploymentConfigsProductionAnalyticsEngineDatasets",
    "DeploymentConfigsProductionBrowsers",
    "DeploymentConfigsProductionD1Databases",
    "DeploymentConfigsProductionDurableObjectNamespaces",
    "DeploymentConfigsProductionHyperdriveBindings",
    "DeploymentConfigsProductionKVNamespaces",
    "DeploymentConfigsProductionLimits",
    "DeploymentConfigsProductionMTLSCertificates",
    "DeploymentConfigsProductionPlacement",
    "DeploymentConfigsProductionQueueProducers",
    "DeploymentConfigsProductionR2Buckets",
    "DeploymentConfigsProductionServices",
    "DeploymentConfigsProductionVectorizeBindings",
    "BuildConfig",
    "Source",
    "SourceConfig",
]


class DeploymentConfigsPreviewEnvVarsPagesPlainTextEnvVar(BaseModel):
    """A plaintext environment variable."""

    type: Literal["plain_text"]

    value: str
    """Environment variable value."""


class DeploymentConfigsPreviewEnvVarsPagesSecretTextEnvVar(BaseModel):
    """An encrypted environment variable."""

    type: Literal["secret_text"]

    value: str
    """Secret value."""


DeploymentConfigsPreviewEnvVars: TypeAlias = Annotated[
    Union[
        Optional[DeploymentConfigsPreviewEnvVarsPagesPlainTextEnvVar],
        Optional[DeploymentConfigsPreviewEnvVarsPagesSecretTextEnvVar],
        None,
    ],
    PropertyInfo(discriminator="type"),
]


class DeploymentConfigsPreviewAIBindings(BaseModel):
    """AI binding."""

    project_id: str


class DeploymentConfigsPreviewAnalyticsEngineDatasets(BaseModel):
    """Analytics Engine binding."""

    dataset: str
    """Name of the dataset."""


class DeploymentConfigsPreviewBrowsers(BaseModel):
    """Browser binding."""

    pass


class DeploymentConfigsPreviewD1Databases(BaseModel):
    """D1 binding."""

    id: str
    """UUID of the D1 database."""


class DeploymentConfigsPreviewDurableObjectNamespaces(BaseModel):
    """Durable Object binding."""

    namespace_id: str
    """ID of the Durable Object namespace."""


class DeploymentConfigsPreviewHyperdriveBindings(BaseModel):
    """Hyperdrive binding."""

    id: str


class DeploymentConfigsPreviewKVNamespaces(BaseModel):
    """KV namespace binding."""

    namespace_id: str
    """ID of the KV namespace."""


class DeploymentConfigsPreviewLimits(BaseModel):
    """Limits for Pages Functions."""

    cpu_ms: int
    """CPU time limit in milliseconds."""


class DeploymentConfigsPreviewMTLSCertificates(BaseModel):
    """mTLS binding."""

    certificate_id: str


class DeploymentConfigsPreviewPlacement(BaseModel):
    """Placement setting used for Pages Functions."""

    mode: str
    """Placement mode."""


class DeploymentConfigsPreviewQueueProducers(BaseModel):
    """Queue Producer binding."""

    name: str
    """Name of the Queue."""


class DeploymentConfigsPreviewR2Buckets(BaseModel):
    """R2 binding."""

    name: str
    """Name of the R2 bucket."""

    jurisdiction: Optional[str] = None
    """Jurisdiction of the R2 bucket."""


class DeploymentConfigsPreviewServices(BaseModel):
    """Service binding."""

    environment: str
    """The Service environment."""

    service: str
    """The Service name."""

    entrypoint: Optional[str] = None
    """The entrypoint to bind to."""


class DeploymentConfigsPreviewVectorizeBindings(BaseModel):
    """Vectorize binding."""

    index_name: str


class DeploymentConfigsPreview(BaseModel):
    """Configs for preview deploys."""

    always_use_latest_compatibility_date: bool
    """Whether to always use the latest compatibility date for Pages Functions."""

    build_image_major_version: int
    """The major version of the build image to use for Pages Functions."""

    compatibility_date: str
    """Compatibility date used for Pages Functions."""

    compatibility_flags: List[str]
    """Compatibility flags used for Pages Functions."""

    env_vars: Optional[Dict[str, Optional[DeploymentConfigsPreviewEnvVars]]] = None
    """Environment variables used for builds and Pages Functions."""

    fail_open: bool
    """Whether to fail open when the deployment config cannot be applied."""

    usage_model: Literal["standard", "bundled", "unbound"]
    """The usage model for Pages Functions."""

    ai_bindings: Optional[Dict[str, DeploymentConfigsPreviewAIBindings]] = None
    """Constellation bindings used for Pages Functions."""

    analytics_engine_datasets: Optional[Dict[str, DeploymentConfigsPreviewAnalyticsEngineDatasets]] = None
    """Analytics Engine bindings used for Pages Functions."""

    browsers: Optional[Dict[str, Optional[DeploymentConfigsPreviewBrowsers]]] = None
    """Browser bindings used for Pages Functions."""

    d1_databases: Optional[Dict[str, DeploymentConfigsPreviewD1Databases]] = None
    """D1 databases used for Pages Functions."""

    durable_object_namespaces: Optional[Dict[str, DeploymentConfigsPreviewDurableObjectNamespaces]] = None
    """Durable Object namespaces used for Pages Functions."""

    hyperdrive_bindings: Optional[Dict[str, DeploymentConfigsPreviewHyperdriveBindings]] = None
    """Hyperdrive bindings used for Pages Functions."""

    kv_namespaces: Optional[Dict[str, DeploymentConfigsPreviewKVNamespaces]] = None
    """KV namespaces used for Pages Functions."""

    limits: Optional[DeploymentConfigsPreviewLimits] = None
    """Limits for Pages Functions."""

    mtls_certificates: Optional[Dict[str, DeploymentConfigsPreviewMTLSCertificates]] = None
    """mTLS bindings used for Pages Functions."""

    placement: Optional[DeploymentConfigsPreviewPlacement] = None
    """Placement setting used for Pages Functions."""

    queue_producers: Optional[Dict[str, DeploymentConfigsPreviewQueueProducers]] = None
    """Queue Producer bindings used for Pages Functions."""

    r2_buckets: Optional[Dict[str, DeploymentConfigsPreviewR2Buckets]] = None
    """R2 buckets used for Pages Functions."""

    services: Optional[Dict[str, DeploymentConfigsPreviewServices]] = None
    """Services used for Pages Functions."""

    vectorize_bindings: Optional[Dict[str, DeploymentConfigsPreviewVectorizeBindings]] = None
    """Vectorize bindings used for Pages Functions."""

    wrangler_config_hash: Optional[str] = None
    """Hash of the Wrangler configuration used for the deployment."""


class DeploymentConfigsProductionEnvVarsPagesPlainTextEnvVar(BaseModel):
    """A plaintext environment variable."""

    type: Literal["plain_text"]

    value: str
    """Environment variable value."""


class DeploymentConfigsProductionEnvVarsPagesSecretTextEnvVar(BaseModel):
    """An encrypted environment variable."""

    type: Literal["secret_text"]

    value: str
    """Secret value."""


DeploymentConfigsProductionEnvVars: TypeAlias = Annotated[
    Union[
        Optional[DeploymentConfigsProductionEnvVarsPagesPlainTextEnvVar],
        Optional[DeploymentConfigsProductionEnvVarsPagesSecretTextEnvVar],
        None,
    ],
    PropertyInfo(discriminator="type"),
]


class DeploymentConfigsProductionAIBindings(BaseModel):
    """AI binding."""

    project_id: str


class DeploymentConfigsProductionAnalyticsEngineDatasets(BaseModel):
    """Analytics Engine binding."""

    dataset: str
    """Name of the dataset."""


class DeploymentConfigsProductionBrowsers(BaseModel):
    """Browser binding."""

    pass


class DeploymentConfigsProductionD1Databases(BaseModel):
    """D1 binding."""

    id: str
    """UUID of the D1 database."""


class DeploymentConfigsProductionDurableObjectNamespaces(BaseModel):
    """Durable Object binding."""

    namespace_id: str
    """ID of the Durable Object namespace."""


class DeploymentConfigsProductionHyperdriveBindings(BaseModel):
    """Hyperdrive binding."""

    id: str


class DeploymentConfigsProductionKVNamespaces(BaseModel):
    """KV namespace binding."""

    namespace_id: str
    """ID of the KV namespace."""


class DeploymentConfigsProductionLimits(BaseModel):
    """Limits for Pages Functions."""

    cpu_ms: int
    """CPU time limit in milliseconds."""


class DeploymentConfigsProductionMTLSCertificates(BaseModel):
    """mTLS binding."""

    certificate_id: str


class DeploymentConfigsProductionPlacement(BaseModel):
    """Placement setting used for Pages Functions."""

    mode: str
    """Placement mode."""


class DeploymentConfigsProductionQueueProducers(BaseModel):
    """Queue Producer binding."""

    name: str
    """Name of the Queue."""


class DeploymentConfigsProductionR2Buckets(BaseModel):
    """R2 binding."""

    name: str
    """Name of the R2 bucket."""

    jurisdiction: Optional[str] = None
    """Jurisdiction of the R2 bucket."""


class DeploymentConfigsProductionServices(BaseModel):
    """Service binding."""

    environment: str
    """The Service environment."""

    service: str
    """The Service name."""

    entrypoint: Optional[str] = None
    """The entrypoint to bind to."""


class DeploymentConfigsProductionVectorizeBindings(BaseModel):
    """Vectorize binding."""

    index_name: str


class DeploymentConfigsProduction(BaseModel):
    """Configs for production deploys."""

    always_use_latest_compatibility_date: bool
    """Whether to always use the latest compatibility date for Pages Functions."""

    build_image_major_version: int
    """The major version of the build image to use for Pages Functions."""

    compatibility_date: str
    """Compatibility date used for Pages Functions."""

    compatibility_flags: List[str]
    """Compatibility flags used for Pages Functions."""

    env_vars: Optional[Dict[str, Optional[DeploymentConfigsProductionEnvVars]]] = None
    """Environment variables used for builds and Pages Functions."""

    fail_open: bool
    """Whether to fail open when the deployment config cannot be applied."""

    usage_model: Literal["standard", "bundled", "unbound"]
    """The usage model for Pages Functions."""

    ai_bindings: Optional[Dict[str, DeploymentConfigsProductionAIBindings]] = None
    """Constellation bindings used for Pages Functions."""

    analytics_engine_datasets: Optional[Dict[str, DeploymentConfigsProductionAnalyticsEngineDatasets]] = None
    """Analytics Engine bindings used for Pages Functions."""

    browsers: Optional[Dict[str, Optional[DeploymentConfigsProductionBrowsers]]] = None
    """Browser bindings used for Pages Functions."""

    d1_databases: Optional[Dict[str, DeploymentConfigsProductionD1Databases]] = None
    """D1 databases used for Pages Functions."""

    durable_object_namespaces: Optional[Dict[str, DeploymentConfigsProductionDurableObjectNamespaces]] = None
    """Durable Object namespaces used for Pages Functions."""

    hyperdrive_bindings: Optional[Dict[str, DeploymentConfigsProductionHyperdriveBindings]] = None
    """Hyperdrive bindings used for Pages Functions."""

    kv_namespaces: Optional[Dict[str, DeploymentConfigsProductionKVNamespaces]] = None
    """KV namespaces used for Pages Functions."""

    limits: Optional[DeploymentConfigsProductionLimits] = None
    """Limits for Pages Functions."""

    mtls_certificates: Optional[Dict[str, DeploymentConfigsProductionMTLSCertificates]] = None
    """mTLS bindings used for Pages Functions."""

    placement: Optional[DeploymentConfigsProductionPlacement] = None
    """Placement setting used for Pages Functions."""

    queue_producers: Optional[Dict[str, DeploymentConfigsProductionQueueProducers]] = None
    """Queue Producer bindings used for Pages Functions."""

    r2_buckets: Optional[Dict[str, DeploymentConfigsProductionR2Buckets]] = None
    """R2 buckets used for Pages Functions."""

    services: Optional[Dict[str, DeploymentConfigsProductionServices]] = None
    """Services used for Pages Functions."""

    vectorize_bindings: Optional[Dict[str, DeploymentConfigsProductionVectorizeBindings]] = None
    """Vectorize bindings used for Pages Functions."""

    wrangler_config_hash: Optional[str] = None
    """Hash of the Wrangler configuration used for the deployment."""


class DeploymentConfigs(BaseModel):
    """Configs for deployments in a project."""

    preview: DeploymentConfigsPreview
    """Configs for preview deploys."""

    production: DeploymentConfigsProduction
    """Configs for production deploys."""


class BuildConfig(BaseModel):
    """Configs for the project build process."""

    web_analytics_tag: Optional[str] = None
    """The classifying tag for analytics."""

    web_analytics_token: Optional[str] = None
    """The auth token for analytics."""

    build_caching: Optional[bool] = None
    """Enable build caching for the project."""

    build_command: Optional[str] = None
    """Command used to build project."""

    destination_dir: Optional[str] = None
    """Assets output directory of the build."""

    root_dir: Optional[str] = None
    """Directory to run the command."""


class SourceConfig(BaseModel):
    deployments_enabled: bool
    """
    Whether to enable automatic deployments when pushing to the source repository.
    When disabled, no deployments (production or preview) will be triggered
    automatically.
    """

    owner: str
    """The owner of the repository."""

    owner_id: str
    """The owner ID of the repository."""

    path_excludes: List[str]
    """A list of paths that should be excluded from triggering a preview deployment.

    Wildcard syntax (`*`) is supported.
    """

    path_includes: List[str]
    """A list of paths that should be watched to trigger a preview deployment.

    Wildcard syntax (`*`) is supported.
    """

    pr_comments_enabled: bool
    """Whether to enable PR comments."""

    preview_branch_excludes: List[str]
    """A list of branches that should not trigger a preview deployment.

    Wildcard syntax (`*`) is supported. Must be used with
    `preview_deployment_setting` set to `custom`.
    """

    preview_branch_includes: List[str]
    """A list of branches that should trigger a preview deployment.

    Wildcard syntax (`*`) is supported. Must be used with
    `preview_deployment_setting` set to `custom`.
    """

    preview_deployment_setting: Literal["all", "none", "custom"]
    """Controls whether commits to preview branches trigger a preview deployment."""

    production_branch: str
    """The production branch of the repository."""

    production_deployments_enabled: bool
    """Whether to trigger a production deployment on commits to the production branch."""

    repo_id: str
    """The ID of the repository."""

    repo_name: str
    """The name of the repository."""


class Source(BaseModel):
    """Configs for the project source control."""

    config: SourceConfig

    type: Literal["github", "gitlab"]
    """The source control management provider."""


class Project(BaseModel):
    id: str
    """ID of the project."""

    canonical_deployment: Optional[Deployment] = None
    """Most recent production deployment of the project."""

    created_on: datetime
    """When the project was created."""

    deployment_configs: DeploymentConfigs
    """Configs for deployments in a project."""

    framework: str
    """Framework the project is using."""

    framework_version: str
    """Version of the framework the project is using."""

    latest_deployment: Optional[Deployment] = None
    """Most recent deployment of the project."""

    name: str
    """Name of the project."""

    preview_script_name: str
    """Name of the preview script."""

    production_branch: str
    """Production branch of the project. Used to identify production deployments."""

    production_script_name: str
    """Name of the production script."""

    uses_functions: Optional[bool] = None
    """Whether the project uses functions."""

    build_config: Optional[BuildConfig] = None
    """Configs for the project build process."""

    domains: Optional[List[str]] = None
    """A list of associated custom domains for the project."""

    source: Optional[Source] = None
    """Configs for the project source control."""

    subdomain: Optional[str] = None
    """The Cloudflare subdomain associated with the project."""
