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

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

from pydantic import Field as FieldInfo

from ...._utils import PropertyInfo
from ...._models import BaseModel
from .consumer_script import ConsumerScript
from ..single_step_migration import SingleStepMigration

__all__ = [
    "ScriptAndVersionSettingEditResponse",
    "Annotations",
    "Binding",
    "BindingWorkersBindingKindAI",
    "BindingWorkersBindingKindAISearch",
    "BindingWorkersBindingKindAISearchNamespace",
    "BindingWorkersBindingKindAnalyticsEngine",
    "BindingWorkersBindingKindAssets",
    "BindingWorkersBindingKindBrowser",
    "BindingWorkersBindingKindD1",
    "BindingWorkersBindingKindDataBlob",
    "BindingWorkersBindingKindDispatchNamespace",
    "BindingWorkersBindingKindDispatchNamespaceOutbound",
    "BindingWorkersBindingKindDispatchNamespaceOutboundParam",
    "BindingWorkersBindingKindDispatchNamespaceOutboundWorker",
    "BindingWorkersBindingKindDurableObjectNamespace",
    "BindingWorkersBindingKindHyperdrive",
    "BindingWorkersBindingKindInherit",
    "BindingWorkersBindingKindImages",
    "BindingWorkersBindingKindJson",
    "BindingWorkersBindingKindKVNamespace",
    "BindingWorkersBindingKindMedia",
    "BindingWorkersBindingKindMTLSCertificate",
    "BindingWorkersBindingKindPlainText",
    "BindingWorkersBindingKindPipelines",
    "BindingWorkersBindingKindQueue",
    "BindingWorkersBindingKindRatelimit",
    "BindingWorkersBindingKindRatelimitSimple",
    "BindingWorkersBindingKindR2Bucket",
    "BindingWorkersBindingKindSecretText",
    "BindingWorkersBindingKindSendEmail",
    "BindingWorkersBindingKindService",
    "BindingWorkersBindingKindTextBlob",
    "BindingWorkersBindingKindVectorize",
    "BindingWorkersBindingKindVersionMetadata",
    "BindingWorkersBindingKindSecretsStoreSecret",
    "BindingWorkersBindingKindFlagship",
    "BindingWorkersBindingKindSecretKey",
    "BindingWorkersBindingKindWorkflow",
    "BindingWorkersBindingKindWasmModule",
    "BindingWorkersBindingKindVPCService",
    "BindingWorkersBindingKindVPCNetwork",
    "CacheOptions",
    "Exports",
    "ExportsWorkersWorkerExport",
    "ExportsWorkersWorkerExportCache",
    "ExportsWorkersDurableObjectExport",
    "ExportsWorkersDurableObjectDeletedExport",
    "ExportsWorkersDurableObjectRenamedExport",
    "ExportsWorkersDurableObjectTransferredExport",
    "ExportsWorkersDurableObjectExpectingTransferExport",
    "ExportsReconciliation",
    "ExportsReconciliationInfo",
    "ExportsReconciliationRenamed",
    "ExportsReconciliationTransferPending",
    "ExportsReconciliationTransferred",
    "ExportsReconciliationWarning",
    "Limits",
    "Migrations",
    "MigrationsWorkersMultipleStepMigrations",
    "Observability",
    "ObservabilityLogs",
    "ObservabilityTraces",
    "Placement",
    "PlacementMode",
    "PlacementRegion",
    "PlacementHostname",
    "PlacementHost",
    "PlacementUnionMember4",
    "PlacementUnionMember5",
    "PlacementUnionMember6",
    "PlacementUnionMember7",
    "PlacementUnionMember7Target",
    "PlacementUnionMember7TargetRegion",
    "PlacementUnionMember7TargetHostname",
    "PlacementUnionMember7TargetHost",
]


class Annotations(BaseModel):
    """Annotations for the Worker version.

    Annotations are not inherited across settings updates; omitting this field means the new version will have no annotations.
    """

    workers_message: Optional[str] = FieldInfo(alias="workers/message", default=None)
    """Human-readable message about the version. Truncated to 1000 bytes if longer."""

    workers_tag: Optional[str] = FieldInfo(alias="workers/tag", default=None)
    """User-provided identifier for the version. Maximum 100 bytes."""

    workers_triggered_by: Optional[str] = FieldInfo(alias="workers/triggered_by", default=None)
    """Operation that triggered the creation of the version.

    This is read-only and set by the server.
    """


class BindingWorkersBindingKindAI(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["ai"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindAISearch(BaseModel):
    instance_name: str
    """The user-chosen instance name.

    Must exist at deploy time. The worker can search, chat, update, and manage
    items/jobs on this instance.
    """

    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["ai_search"]
    """The kind of resource that the binding provides."""

    namespace: Optional[str] = None
    """The namespace the instance belongs to.

    Defaults to "default" if omitted. Customers who don't use namespaces can simply
    omit this field.
    """


class BindingWorkersBindingKindAISearchNamespace(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    namespace: str
    """The user-chosen namespace name.

    Must exist before deploy -- Wrangler handles auto-creation on deploy failure (R2
    bucket pattern). The "default" namespace is auto-created by config-api for new
    accounts. Grants full access (CRUD + search + chat) to all instances within the
    namespace.
    """

    type: Literal["ai_search_namespace"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindAnalyticsEngine(BaseModel):
    dataset: str
    """The name of the dataset to bind to."""

    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["analytics_engine"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindAssets(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["assets"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindBrowser(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["browser"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindD1(BaseModel):
    database_id: str
    """Identifier of the D1 database to bind to."""

    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["d1"]
    """The kind of resource that the binding provides."""

    id: Optional[str] = None
    """Identifier of the D1 database to bind to."""


class BindingWorkersBindingKindDataBlob(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    part: str
    """The name of the file containing the data content.

    Only accepted for `service worker syntax` Workers.
    """

    type: Literal["data_blob"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindDispatchNamespaceOutboundParam(BaseModel):
    name: str
    """Name of the parameter."""


class BindingWorkersBindingKindDispatchNamespaceOutboundWorker(BaseModel):
    """Outbound worker."""

    entrypoint: Optional[str] = None
    """Entrypoint to invoke on the outbound worker."""

    environment: Optional[str] = None
    """Environment of the outbound worker."""

    service: Optional[str] = None
    """Name of the outbound worker."""


class BindingWorkersBindingKindDispatchNamespaceOutbound(BaseModel):
    """Outbound worker."""

    params: Optional[List[BindingWorkersBindingKindDispatchNamespaceOutboundParam]] = None
    """
    Pass information from the Dispatch Worker to the Outbound Worker through the
    parameters.
    """

    worker: Optional[BindingWorkersBindingKindDispatchNamespaceOutboundWorker] = None
    """Outbound worker."""


class BindingWorkersBindingKindDispatchNamespace(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    namespace: str
    """The name of the dispatch namespace."""

    type: Literal["dispatch_namespace"]
    """The kind of resource that the binding provides."""

    outbound: Optional[BindingWorkersBindingKindDispatchNamespaceOutbound] = None
    """Outbound worker."""


class BindingWorkersBindingKindDurableObjectNamespace(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["durable_object_namespace"]
    """The kind of resource that the binding provides."""

    class_name: Optional[str] = None
    """The exported class name of the Durable Object."""

    dispatch_namespace: Optional[str] = None
    """The dispatch namespace the Durable Object script belongs to."""

    environment: Optional[str] = None
    """The environment of the script_name to bind to."""

    namespace_id: Optional[str] = None
    """Namespace identifier tag."""

    script_name: Optional[str] = None
    """
    The script where the Durable Object is defined, if it is external to this
    Worker.
    """


class BindingWorkersBindingKindHyperdrive(BaseModel):
    id: str
    """Identifier of the Hyperdrive connection to bind to."""

    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["hyperdrive"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindInherit(BaseModel):
    name: str
    """The name of the inherited binding."""

    type: Literal["inherit"]
    """The kind of resource that the binding provides."""

    old_name: Optional[str] = None
    """The old name of the inherited binding.

    If set, the binding will be renamed from `old_name` to `name` in the new
    version. If not set, the binding will keep the same name between versions.
    """

    version_id: Optional[str] = None
    """
    Identifier for the version to inherit the binding from, which can be the version
    ID or the literal "latest" to inherit from the latest version. Defaults to
    inheriting the binding from the latest version.
    """


class BindingWorkersBindingKindImages(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["images"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindJson(BaseModel):
    json_: object = FieldInfo(alias="json")
    """JSON data to use."""

    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["json"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindKVNamespace(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    namespace_id: str
    """Namespace identifier tag."""

    type: Literal["kv_namespace"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindMedia(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["media"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindMTLSCertificate(BaseModel):
    certificate_id: str
    """Identifier of the certificate to bind to."""

    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["mtls_certificate"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindPlainText(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    text: str
    """The text value to use."""

    type: Literal["plain_text"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindPipelines(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    pipeline: str
    """Name of the Pipeline to bind to."""

    type: Literal["pipelines"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindQueue(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    queue_name: str
    """Name of the Queue to bind to."""

    type: Literal["queue"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindRatelimitSimple(BaseModel):
    """The rate limit configuration."""

    limit: float
    """The limit (requests per period)."""

    period: int
    """The period in seconds."""

    mitigation_timeout: Optional[int] = None
    """
    Duration in seconds to apply the mitigation action after the rate limit is
    exceeded. Valid values are 0 (disabled), 10, or multiples of 60 up to 86400.
    Must be greater than or equal to the period when non-zero.
    """


class BindingWorkersBindingKindRatelimit(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    namespace_id: str
    """Identifier of the rate limit namespace to bind to."""

    simple: BindingWorkersBindingKindRatelimitSimple
    """The rate limit configuration."""

    type: Literal["ratelimit"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindR2Bucket(BaseModel):
    bucket_name: str
    """R2 bucket to bind to."""

    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["r2_bucket"]
    """The kind of resource that the binding provides."""

    jurisdiction: Optional[Literal["eu", "fedramp", "fedramp-high"]] = None
    """
    The
    [jurisdiction](https://developers.cloudflare.com/r2/reference/data-location/#jurisdictional-restrictions)
    of the R2 bucket.
    """


class BindingWorkersBindingKindSecretText(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["secret_text"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindSendEmail(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["send_email"]
    """The kind of resource that the binding provides."""

    allowed_destination_addresses: Optional[List[str]] = None
    """List of allowed destination addresses."""

    allowed_sender_addresses: Optional[List[str]] = None
    """List of allowed sender addresses."""

    destination_address: Optional[str] = None
    """Destination address for the email."""


class BindingWorkersBindingKindService(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    service: str
    """Name of Worker to bind to."""

    type: Literal["service"]
    """The kind of resource that the binding provides."""

    entrypoint: Optional[str] = None
    """Entrypoint to invoke on the target Worker."""

    environment: Optional[str] = None
    """Optional environment if the Worker utilizes one."""


class BindingWorkersBindingKindTextBlob(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    part: str
    """The name of the file containing the text content.

    Only accepted for `service worker syntax` Workers.
    """

    type: Literal["text_blob"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindVectorize(BaseModel):
    index_name: str
    """Name of the Vectorize index to bind to."""

    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["vectorize"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindVersionMetadata(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["version_metadata"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindSecretsStoreSecret(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    secret_name: str
    """Name of the secret in the store."""

    store_id: str
    """ID of the store containing the secret."""

    type: Literal["secrets_store_secret"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindFlagship(BaseModel):
    app_id: str
    """ID of the Flagship app to bind to for feature flag evaluation."""

    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["flagship"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindSecretKey(BaseModel):
    algorithm: object
    """Algorithm-specific key parameters.

    [Learn more](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#algorithm).
    """

    format: Literal["raw", "pkcs8", "spki", "jwk"]
    """Data format of the key.

    [Learn more](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#format).
    """

    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["secret_key"]
    """The kind of resource that the binding provides."""

    usages: List[Literal["encrypt", "decrypt", "sign", "verify", "deriveKey", "deriveBits", "wrapKey", "unwrapKey"]]
    """Allowed operations with the key.

    [Learn more](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#keyUsages).
    """


class BindingWorkersBindingKindWorkflow(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["workflow"]
    """The kind of resource that the binding provides."""

    workflow_name: str
    """Name of the Workflow to bind to."""

    class_name: Optional[str] = None
    """Class name of the Workflow.

    Should only be provided if the Workflow belongs to this script.
    """

    script_name: Optional[str] = None
    """Script name that contains the Workflow.

    If not provided, defaults to this script name.
    """


class BindingWorkersBindingKindWasmModule(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    part: str
    """The name of the file containing the WebAssembly module content.

    Only accepted for `service worker syntax` Workers.
    """

    type: Literal["wasm_module"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindVPCService(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    service_id: str
    """Identifier of the VPC service to bind to."""

    type: Literal["vpc_service"]
    """The kind of resource that the binding provides."""


class BindingWorkersBindingKindVPCNetwork(BaseModel):
    name: str
    """A JavaScript variable name for the binding."""

    type: Literal["vpc_network"]
    """The kind of resource that the binding provides."""

    network_id: Optional[str] = None
    """Identifier of the network to bind to.

    Only "cf1:network" is currently supported. Mutually exclusive with tunnel_id.
    """

    tunnel_id: Optional[str] = None
    """UUID of the Cloudflare Tunnel to bind to. Mutually exclusive with network_id."""


Binding: TypeAlias = Annotated[
    Union[
        BindingWorkersBindingKindAI,
        BindingWorkersBindingKindAISearch,
        BindingWorkersBindingKindAISearchNamespace,
        BindingWorkersBindingKindAnalyticsEngine,
        BindingWorkersBindingKindAssets,
        BindingWorkersBindingKindBrowser,
        BindingWorkersBindingKindD1,
        BindingWorkersBindingKindDataBlob,
        BindingWorkersBindingKindDispatchNamespace,
        BindingWorkersBindingKindDurableObjectNamespace,
        BindingWorkersBindingKindHyperdrive,
        BindingWorkersBindingKindInherit,
        BindingWorkersBindingKindImages,
        BindingWorkersBindingKindJson,
        BindingWorkersBindingKindKVNamespace,
        BindingWorkersBindingKindMedia,
        BindingWorkersBindingKindMTLSCertificate,
        BindingWorkersBindingKindPlainText,
        BindingWorkersBindingKindPipelines,
        BindingWorkersBindingKindQueue,
        BindingWorkersBindingKindRatelimit,
        BindingWorkersBindingKindR2Bucket,
        BindingWorkersBindingKindSecretText,
        BindingWorkersBindingKindSendEmail,
        BindingWorkersBindingKindService,
        BindingWorkersBindingKindTextBlob,
        BindingWorkersBindingKindVectorize,
        BindingWorkersBindingKindVersionMetadata,
        BindingWorkersBindingKindSecretsStoreSecret,
        BindingWorkersBindingKindFlagship,
        BindingWorkersBindingKindSecretKey,
        BindingWorkersBindingKindWorkflow,
        BindingWorkersBindingKindWasmModule,
        BindingWorkersBindingKindVPCService,
        BindingWorkersBindingKindVPCNetwork,
    ],
    PropertyInfo(discriminator="type"),
]


class CacheOptions(BaseModel):
    """Global CacheW configuration for the Worker.

    When caching is on,
    the platform provisions a `cloudflare.app` zone for the Worker.
    A `type: worker` entry in the `exports` map can override this
    value for a single entrypoint.
    """

    enabled: bool
    """Whether caching is enabled for this Worker."""

    cross_version_cache: Optional[bool] = None
    """Whether cached responses are shared across Worker version uploads.

    This is independent of `enabled`. It can stay true while caching is off, so the
    preference survives turning caching off and back on.
    """


class ExportsWorkersWorkerExportCache(BaseModel):
    """Cache override for this entrypoint.

    Overrides the Worker's
    global `cache_options.enabled` for this entrypoint only.
    """

    enabled: bool
    """Whether caching is enabled for this entrypoint."""


class ExportsWorkersWorkerExport(BaseModel):
    """A named Worker entrypoint export (`type: worker`).

    Worker
    entrypoints are always live (`state: created`) and carry no
    storage or lifecycle fields. The optional `cache` block overrides
    the Worker's global `cache_options.enabled` for this entrypoint.
    """

    type: Literal["worker"]
    """Marks this entry as a Worker entrypoint export."""

    cache: Optional[ExportsWorkersWorkerExportCache] = None
    """Cache override for this entrypoint.

    Overrides the Worker's global `cache_options.enabled` for this entrypoint only.
    """

    state: Optional[Literal["created"]] = None
    """Live export. May be omitted; defaults to `created`."""


class ExportsWorkersDurableObjectExport(BaseModel):
    """A live Durable Object export (`state: created`, the default).

    The
    platform auto-provisions the namespace on first deploy, matches it
    on subsequent deploys, and never mutates or deletes it as a side
    effect of a code-only change. `storage` is required; `renamed_to`,
    `transferred_to` and `transfer_from` are not allowed on a live
    entry.
    """

    storage: Literal["sqlite", "legacy-kv"]
    """Durable Object storage backend.

    `sqlite` is the recommended (and only) backend for new namespaces. `legacy-kv`
    is accepted only for a class whose namespace already exists as KV-backed; the
    `exports` flow never provisions a new `legacy-kv` namespace.
    """

    type: Literal["durable-object"]
    """Marks this entry as a Durable Object export."""

    container: Optional[str] = None
    """
    Name of the container (declared in the upload's `metadata.containers`) that
    backs this Durable Object. When set, the namespace is container-enabled. Valid
    only on live entries.
    """

    state: Optional[Literal["created"]] = None
    """Live export. May be omitted; defaults to `created`."""


class ExportsWorkersDurableObjectDeletedExport(BaseModel):
    """
    A `deleted` tombstone: retires the provisioned namespace for this
    class and all of its data. The class must be absent from the
    uploaded code and no other Worker in the account may bind to the
    namespace, otherwise the deploy is rejected. No other fields are
    allowed. Deletion is irreversible.
    """

    state: Literal["deleted"]
    """Tombstone that deletes the namespace."""

    type: Literal["durable-object"]
    """Marks this entry as a Durable Object export."""


class ExportsWorkersDurableObjectRenamedExport(BaseModel):
    """
    A `renamed` tombstone: rewrites the provisioned namespace's class
    name from this map key to `renamed_to`. The source class may stay
    in code during the rollout window (an info notice is emitted).
    `storage`, `transferred_to` and `transfer_from` are not allowed.
    """

    state: Literal["renamed"]
    """Tombstone that renames the namespace's class."""

    type: Literal["durable-object"]
    """Marks this entry as a Durable Object export."""


class ExportsWorkersDurableObjectTransferredExport(BaseModel):
    """
    A `transferred` tombstone (source side of a two-phase transfer):
    hands ownership of the provisioned namespace to another script in
    the same account, named by `transferred_to`. The target must have
    already deployed a matching `expecting-transfer` entry. The source
    class may stay in code during the rollout window (an info notice
    is emitted). `storage`, `renamed_to` and `transfer_from` are not
    allowed.
    """

    state: Literal["transferred"]
    """Tombstone that transfers the namespace to another script."""

    type: Literal["durable-object"]
    """Marks this entry as a Durable Object export."""


class ExportsWorkersDurableObjectExpectingTransferExport(BaseModel):
    """The target side of a two-phase transfer (`state:
    expecting-transfer`).

    Declares that this script expects to receive
    a namespace for this class from the `transfer_from` script. This
    is a live entry, not a tombstone: bindings resolve through the
    source's namespace until the source commits with a `transferred`
    tombstone. `storage` and `transfer_from` are required; `renamed_to`
    and `transferred_to` are not allowed.
    """

    state: Literal["expecting-transfer"]
    """Target side of a two-phase transfer."""

    storage: Literal["sqlite", "legacy-kv"]
    """Durable Object storage backend.

    `sqlite` is the recommended (and only) backend for new namespaces. `legacy-kv`
    is accepted only for a class whose namespace already exists as KV-backed; the
    `exports` flow never provisions a new `legacy-kv` namespace.
    """

    transfer_from: str
    """The source script name to receive the namespace from.

    Must be in the same account and dispatch-namespace context. Present on reads for
    `expecting-transfer` entries.
    """

    type: Literal["durable-object"]
    """Marks this entry as a Durable Object export."""

    container: Optional[str] = None
    """
    Name of the container (declared in the upload's `metadata.containers`) that
    backs this Durable Object once the transfer settles. Valid only on live entries.
    """


Exports: TypeAlias = Annotated[
    Union[
        ExportsWorkersWorkerExport,
        ExportsWorkersDurableObjectExport,
        ExportsWorkersDurableObjectDeletedExport,
        ExportsWorkersDurableObjectRenamedExport,
        ExportsWorkersDurableObjectTransferredExport,
        ExportsWorkersDurableObjectExpectingTransferExport,
    ],
    PropertyInfo(discriminator="type"),
]


class ExportsReconciliationInfo(BaseModel):
    """A non-blocking reconciliation info entry.

    Emitted for stale
    tombstones (a no-op on this deploy) and for tombstones applied
    with the source class still in code (the supported zero-downtime
    rollout pattern).
    """

    class_: str = FieldInfo(alias="class")
    """The class name the info entry is about."""

    message: str
    """Human-readable explanation."""

    scenario: Literal[
        "code_class_not_in_exports",
        "provisioned_class_missing_from_config",
        "config_export_not_in_code",
        "config_references_nonexistent_class",
        "orphaned_provisioned_namespace",
        "storage_type_mismatch",
        "free_tier_requires_sqlite",
        "invalid_export",
        "tombstone_delete_class_still_in_code",
        "tombstone_delete_blocked_by_external_bindings",
        "tombstone_renamed_to_occupied",
        "transferred_pending_not_found",
        "transferred_target_missing",
        "transferred_target_mismatch",
        "phase_one_transfer_source_missing",
        "phase_one_transfer_source_namespace_missing",
        "phase_one_transfer_target_class_provisioned",
        "phase_one_transfer_after_commit_mismatch",
        "phase_one_transfer_duplicate",
        "phase_one_transfer_target_in_dispatch_namespace",
        "phase_one_transfer_source_in_dispatch_namespace",
        "transferred_source_in_dispatch_namespace",
        "transferred_target_in_dispatch_namespace",
        "container_undeclared_reference",
        "container_class_not_durable_object",
        "container_wiring_inconsistent",
        "container_multiple_durable_objects",
        "transfer_container_parity_mismatch",
        "transfer_container_parity_mismatch_on_commit",
        "tombstone_class_still_in_code",
        "stale_tombstone",
        "transfer_receive_already_applied",
        "transfer_receive_cleanup_complete",
    ]
    """
    Stable, machine-readable tag identifying which reconciliation scenario produced
    an error, warning, or info entry. Clients may branch on this value instead of
    parsing `message`.
    """

    namespace_id: Optional[str] = None
    """The provisioned namespace the entry relates to, when applicable."""

    referencing_scripts: Optional[List[str]] = None
    """Other Workers in the account that still bind to the affected class.

    Advisory: while non-empty the tombstone is not yet safe to remove — redeploy
    these Workers with bindings re-pointed first.
    """


class ExportsReconciliationRenamed(BaseModel):
    """A single applied `renamed` tombstone."""

    from_: str = FieldInfo(alias="from")
    """The original (source) class name."""

    to: str
    """The new class name (`renamed_to`)."""


class ExportsReconciliationTransferPending(BaseModel):
    """
    A single phase-1 transfer hint recorded on the target side (a live
    `expecting-transfer` entry).
    """

    class_: str = FieldInfo(alias="class")
    """The target-side class name awaiting transfer."""

    from_: str = FieldInfo(alias="from")
    """The source script the namespace will be transferred from."""


class ExportsReconciliationTransferred(BaseModel):
    """A single committed `transferred` tombstone (phase-2 commit)."""

    class_: str = FieldInfo(alias="class")
    """The source class name that was transferred."""

    phase: Literal["committed"]
    """The transfer phase. Currently always `committed`."""

    to: str
    """The destination script that now owns the namespace."""


class ExportsReconciliationWarning(BaseModel):
    """A non-blocking reconciliation warning.

    Reserved: no scenario
    populates this array today (`code_class_not_in_exports` is
    surfaced as info and `provisioned_class_missing_from_config` is a
    hard error). Clients should still surface any entries that appear.
    """

    class_: str = FieldInfo(alias="class")
    """The class name the warning is about."""

    message: str
    """Human-readable explanation of the warning."""

    scenario: Literal[
        "code_class_not_in_exports",
        "provisioned_class_missing_from_config",
        "config_export_not_in_code",
        "config_references_nonexistent_class",
        "orphaned_provisioned_namespace",
        "storage_type_mismatch",
        "free_tier_requires_sqlite",
        "invalid_export",
        "tombstone_delete_class_still_in_code",
        "tombstone_delete_blocked_by_external_bindings",
        "tombstone_renamed_to_occupied",
        "transferred_pending_not_found",
        "transferred_target_missing",
        "transferred_target_mismatch",
        "phase_one_transfer_source_missing",
        "phase_one_transfer_source_namespace_missing",
        "phase_one_transfer_target_class_provisioned",
        "phase_one_transfer_after_commit_mismatch",
        "phase_one_transfer_duplicate",
        "phase_one_transfer_target_in_dispatch_namespace",
        "phase_one_transfer_source_in_dispatch_namespace",
        "transferred_source_in_dispatch_namespace",
        "transferred_target_in_dispatch_namespace",
        "container_undeclared_reference",
        "container_class_not_durable_object",
        "container_wiring_inconsistent",
        "container_multiple_durable_objects",
        "transfer_container_parity_mismatch",
        "transfer_container_parity_mismatch_on_commit",
        "tombstone_class_still_in_code",
        "stale_tombstone",
        "transfer_receive_already_applied",
        "transfer_receive_cleanup_complete",
    ]
    """
    Stable, machine-readable tag identifying which reconciliation scenario produced
    an error, warning, or info entry. Clients may branch on this value instead of
    parsing `message`.
    """

    namespace_id: Optional[str] = None
    """The provisioned namespace the warning relates to, when applicable."""


class ExportsReconciliation(BaseModel):
    """Summary of the declarative exports reconciliation that ran on
    this upload.

    Populated only when the uploaded metadata included
    an `exports` block. Durable Object entries drive reconciliation;
    `type: worker` entries do not contribute to this summary.
    """

    created: List[str]
    """Class names for which a new namespace was provisioned."""

    deleted: List[str]
    """Class names whose namespace was deleted by a `deleted` tombstone."""

    info: List[ExportsReconciliationInfo]
    """
    Non-blocking info entries (stale tombstones, tombstone applied with class still
    in code). See `exports_reconciliation_info`.
    """

    removable_entries: List[str]
    """
    Source class names whose tombstone entry is now stale and safe to delete from
    `exports` (no remaining referencing scripts).
    """

    renamed: List[ExportsReconciliationRenamed]
    """Applied `renamed` tombstones."""

    transfer_pending: List[ExportsReconciliationTransferPending]
    """Phase-1 transfer hints recorded on the target side."""

    transferred: List[ExportsReconciliationTransferred]
    """Committed `transferred` tombstones (phase-2)."""

    updated: List[str]
    """Class names whose provisioned namespace was mutated in place."""

    warnings: List[ExportsReconciliationWarning]
    """Non-blocking warnings. See `exports_reconciliation_warning`."""


class Limits(BaseModel):
    """Limits to apply for this Worker."""

    cpu_ms: Optional[int] = None
    """The amount of CPU time this Worker can use in milliseconds."""

    subrequests: Optional[int] = None
    """The number of subrequests this Worker can make per request."""


class MigrationsWorkersMultipleStepMigrations(BaseModel):
    pass


Migrations: TypeAlias = Union[SingleStepMigration, MigrationsWorkersMultipleStepMigrations]


class ObservabilityLogs(BaseModel):
    """Log settings for the Worker."""

    enabled: bool
    """Whether logs are enabled for the Worker."""

    invocation_logs: bool
    """
    Whether
    [invocation logs](https://developers.cloudflare.com/workers/observability/logs/workers-logs/#invocation-logs)
    are enabled for the Worker.
    """

    destinations: Optional[List[str]] = None
    """A list of destinations where logs will be exported to."""

    head_sampling_rate: Optional[float] = None
    """The sampling rate for logs. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1."""

    persist: Optional[bool] = None
    """Whether log persistence is enabled for the Worker."""


class ObservabilityTraces(BaseModel):
    """Trace settings for the Worker."""

    destinations: Optional[List[str]] = None
    """A list of destinations where traces will be exported to."""

    enabled: Optional[bool] = None
    """Whether traces are enabled for the Worker."""

    head_sampling_rate: Optional[float] = None
    """The sampling rate for traces. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1."""

    persist: Optional[bool] = None
    """Whether trace persistence is enabled for the Worker."""

    propagation_policy: Optional[Literal["authenticated", "accept"]] = None
    """
    Controls how inbound trace context (traceparent/tracestate) headers on incoming
    requests are handled. "authenticated" (default) honors inbound trace context
    only when accompanied by a valid trace auth token. "accept" unconditionally
    accepts inbound trace context. Requires the trace propagation feature to be
    enabled.
    """


class Observability(BaseModel):
    """Observability settings for the Worker."""

    enabled: bool
    """Whether observability is enabled for the Worker."""

    head_sampling_rate: Optional[float] = None
    """The sampling rate for incoming requests.

    From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.
    """

    logs: Optional[ObservabilityLogs] = None
    """Log settings for the Worker."""

    traces: Optional[ObservabilityTraces] = None
    """Trace settings for the Worker."""


class PlacementMode(BaseModel):
    mode: Literal["smart"]
    """
    Enables
    [Smart Placement](https://developers.cloudflare.com/workers/configuration/smart-placement).
    """


class PlacementRegion(BaseModel):
    region: str
    """Cloud region for targeted placement in format 'provider:region'."""


class PlacementHostname(BaseModel):
    hostname: str
    """HTTP hostname for targeted placement."""


class PlacementHost(BaseModel):
    host: str
    """TCP host and port for targeted placement."""


class PlacementUnionMember4(BaseModel):
    mode: Literal["targeted"]
    """Targeted placement mode."""

    region: str
    """Cloud region for targeted placement in format 'provider:region'."""


class PlacementUnionMember5(BaseModel):
    hostname: str
    """HTTP hostname for targeted placement."""

    mode: Literal["targeted"]
    """Targeted placement mode."""


class PlacementUnionMember6(BaseModel):
    host: str
    """TCP host and port for targeted placement."""

    mode: Literal["targeted"]
    """Targeted placement mode."""


class PlacementUnionMember7TargetRegion(BaseModel):
    region: str
    """Cloud region in format 'provider:region'."""


class PlacementUnionMember7TargetHostname(BaseModel):
    hostname: str
    """HTTP hostname for targeted placement."""


class PlacementUnionMember7TargetHost(BaseModel):
    host: str
    """TCP host:port for targeted placement."""


PlacementUnionMember7Target: TypeAlias = Union[
    PlacementUnionMember7TargetRegion, PlacementUnionMember7TargetHostname, PlacementUnionMember7TargetHost
]


class PlacementUnionMember7(BaseModel):
    mode: Literal["targeted"]
    """Targeted placement mode."""

    target: List[PlacementUnionMember7Target]
    """Array of placement targets (currently limited to single target)."""


Placement: TypeAlias = Union[
    PlacementMode,
    PlacementRegion,
    PlacementHostname,
    PlacementHost,
    PlacementUnionMember4,
    PlacementUnionMember5,
    PlacementUnionMember6,
    PlacementUnionMember7,
]


class ScriptAndVersionSettingEditResponse(BaseModel):
    annotations: Optional[Annotations] = None
    """Annotations for the Worker version.

    Annotations are not inherited across settings updates; omitting this field means
    the new version will have no annotations.
    """

    bindings: Optional[List[Binding]] = None
    """List of bindings attached to a Worker.

    You can find more about bindings on our docs:
    https://developers.cloudflare.com/workers/configuration/multipart-upload-metadata/#bindings.
    """

    cache_options: Optional[CacheOptions] = None
    """Global CacheW configuration for the Worker.

    When caching is on, the platform provisions a `cloudflare.app` zone for the
    Worker. A `type: worker` entry in the `exports` map can override this value for
    a single entrypoint.
    """

    compatibility_date: Optional[str] = None
    """Date indicating targeted support in the Workers runtime.

    Backwards incompatible fixes to the runtime following this date will not affect
    this Worker.
    """

    compatibility_flags: Optional[List[str]] = None
    """Flags that enable or disable certain features in the Workers runtime.

    Used to enable upcoming features or opt in or out of specific changes not
    included in a `compatibility_date`.
    """

    exports_reconciliation: Optional[ExportsReconciliation] = None
    """Summary of the declarative exports reconciliation that ran on this upload.

    Populated only when the uploaded metadata included an `exports` block. Durable
    Object entries drive reconciliation; `type: worker` entries do not contribute to
    this summary.
    """

    limits: Optional[Limits] = None
    """Limits to apply for this Worker."""

    logpush: Optional[bool] = None
    """Whether Logpush is turned on for the Worker."""

    observability: Optional[Observability] = None
    """Observability settings for the Worker."""

    placement: Optional[Placement] = None
    """
    Configuration for
    [Smart Placement](https://developers.cloudflare.com/workers/configuration/smart-placement).
    Specify mode='smart' for Smart Placement, or one of region/hostname/host.
    """

    tags: Optional[List[str]] = None
    """Tags associated with the Worker."""

    tail_consumers: Optional[List[ConsumerScript]] = None
    """List of Workers that will consume logs from the attached Worker."""

    usage_model: Optional[Literal["standard", "bundled", "unbound"]] = None
    """Usage model for the Worker invocations."""
