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

from __future__ import annotations
from .workflowstatus import WorkflowStatus
from datetime import datetime
import pydantic
from pydantic import model_serializer
from ttd_workflows.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from typing_extensions import Annotated, NotRequired, TypedDict


class StandardJobStatusResponseTypedDict(TypedDict):
    id: int
    r"""The ID of the job."""
    created_at_utc: datetime
    r"""The UTC date and time that the job was created."""
    status: WorkflowStatus
    completed_at_utc: NotRequired[Nullable[datetime]]
    r"""The UTC data and time that the job completed."""
    completion_percentage: NotRequired[Nullable[float]]
    r"""The job completion percentage."""
    url: NotRequired[Nullable[str]]
    r"""The URL from which the job result can be downloaded."""
    raw_result: NotRequired[Nullable[str]]
    r"""The raw job result if the response is less than or equal to 20MB in size.
    If the job result is larger than 20MB, then null is returned.
    """
    errors: NotRequired[Nullable[str]]
    r"""A list of errors encountered during workflow processing."""


class StandardJobStatusResponse(BaseModel):
    id: int
    r"""The ID of the job."""

    created_at_utc: Annotated[datetime, pydantic.Field(alias="createdAtUtc")]
    r"""The UTC date and time that the job was created."""

    status: WorkflowStatus

    completed_at_utc: Annotated[
        OptionalNullable[datetime], pydantic.Field(alias="completedAtUtc")
    ] = UNSET
    r"""The UTC data and time that the job completed."""

    completion_percentage: Annotated[
        OptionalNullable[float], pydantic.Field(alias="completionPercentage")
    ] = UNSET
    r"""The job completion percentage."""

    url: OptionalNullable[str] = UNSET
    r"""The URL from which the job result can be downloaded."""

    raw_result: Annotated[OptionalNullable[str], pydantic.Field(alias="rawResult")] = (
        UNSET
    )
    r"""The raw job result if the response is less than or equal to 20MB in size.
    If the job result is larger than 20MB, then null is returned.
    """

    errors: OptionalNullable[str] = UNSET
    r"""A list of errors encountered during workflow processing."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "completedAtUtc",
            "completionPercentage",
            "url",
            "rawResult",
            "errors",
        ]
        nullable_fields = [
            "completedAtUtc",
            "completionPercentage",
            "url",
            "rawResult",
            "errors",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

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

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
