"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .v2deploydeploymentstep import (
    V2DeployDeploymentStep,
    V2DeployDeploymentStepTypedDict,
)
from enum import Enum
import pydantic
from pydantic import field_serializer, model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict
from unkey.py import models, utils
from unkey.py.types import BaseModel, UNSET_SENTINEL


class Status(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Current deployment status"""

    UNSPECIFIED = "UNSPECIFIED"
    PENDING = "PENDING"
    STARTING = "STARTING"
    BUILDING = "BUILDING"
    DEPLOYING = "DEPLOYING"
    NETWORK = "NETWORK"
    FINALIZING = "FINALIZING"
    READY = "READY"
    FAILED = "FAILED"
    SKIPPED = "SKIPPED"
    AWAITING_APPROVAL = "AWAITING_APPROVAL"
    STOPPED = "STOPPED"


class V2DeployGetDeploymentResponseDataTypedDict(TypedDict):
    id: str
    r"""Unique deployment identifier"""
    status: Status
    r"""Current deployment status"""
    error_message: NotRequired[str]
    r"""Error message if deployment failed"""
    hostnames: NotRequired[List[str]]
    r"""Hostnames associated with this deployment"""
    steps: NotRequired[List[V2DeployDeploymentStepTypedDict]]
    r"""Deployment steps with status and messages"""


class V2DeployGetDeploymentResponseData(BaseModel):
    id: str
    r"""Unique deployment identifier"""

    status: Status
    r"""Current deployment status"""

    error_message: Annotated[Optional[str], pydantic.Field(alias="errorMessage")] = None
    r"""Error message if deployment failed"""

    hostnames: Optional[List[str]] = None
    r"""Hostnames associated with this deployment"""

    steps: Optional[List[V2DeployDeploymentStep]] = None
    r"""Deployment steps with status and messages"""

    @field_serializer("status")
    def serialize_status(self, value):
        if isinstance(value, str):
            try:
                return models.Status(value)
            except ValueError:
                return value
        return value

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["errorMessage", "hostnames", "steps"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


try:
    V2DeployGetDeploymentResponseData.model_rebuild()
except NameError:
    pass
