# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from .acp_type import AcpType
from .sdk_type import SdkType
from .version_status import VersionStatus


class VersionResponse(UniversalBaseModel):
    """
    Full version details.
    """

    acp_type: AcpType = pydantic.Field()
    """
    Type of ACP server (sync or async)
    """

    author_email: str = pydantic.Field()
    """
    Commit author email
    """

    author_name: str = pydantic.Field()
    """
    Commit author name
    """

    branch_id: str = pydantic.Field()
    """
    Parent branch ID
    """

    created_at: typing.Optional[dt.datetime] = pydantic.Field(default=None)
    """
    Creation timestamp
    """

    deployed_at: dt.datetime = pydantic.Field()
    """
    When this version was deployed
    """

    failure_diagnostics: typing.Optional[typing.Dict[str, typing.Optional[str]]] = pydantic.Field(default=None)
    """
    User-facing failure diagnostics with 'title', 'description', and 'action' fields
    """

    failure_reason: typing.Optional[str] = pydantic.Field(default=None)
    """
    Classified failure reason when status is FAILED (e.g., 'image_pull_failed', 'crash_loop', 'scheduling_failed')
    """

    git_branch: str = pydantic.Field()
    """
    Git branch name
    """

    git_hash: str = pydantic.Field()
    """
    Git commit hash
    """

    git_message: typing.Optional[str] = pydantic.Field(default=None)
    """
    Git commit message
    """

    id: str = pydantic.Field()
    """
    Version ID
    """

    image_expires_at: typing.Optional[dt.datetime] = pydantic.Field(default=None)
    """
    When image expires (for rollback window)
    """

    image_url: str = pydantic.Field()
    """
    Container image URL
    """

    is_dirty: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Whether the commit had uncommitted changes
    """

    last_rollback_at: typing.Optional[dt.datetime] = pydantic.Field(default=None)
    """
    Timestamp when this version was last rolled back TO
    """

    replicas: typing.Optional[int] = pydantic.Field(default=None)
    """
    Current pod count for this version
    """

    retired_at: typing.Optional[dt.datetime] = pydantic.Field(default=None)
    """
    When version was retired
    """

    rollback_count: typing.Optional[int] = pydantic.Field(default=None)
    """
    Number of rollbacks to this version
    """

    rolled_back_at: typing.Optional[dt.datetime] = pydantic.Field(default=None)
    """
    Timestamp when this version was rolled back FROM
    """

    sdk_type: SdkType = pydantic.Field()
    """
    SDK type for agent runtime
    """

    status: VersionStatus = pydantic.Field()
    """
    Version lifecycle status
    """

    updated_at: typing.Optional[dt.datetime] = pydantic.Field(default=None)
    """
    Last update timestamp
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
