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

from __future__ import annotations
from .contexttaskmetadata import ContextTaskMetadata, ContextTaskMetadataTypedDict
from .contexttoolinfo import ContextToolInfo, ContextToolInfoTypedDict
from .step import Step, StepTypedDict
from .variable import Variable, VariableTypedDict
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from syllable_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from syllable_sdk.utils import validate_const
from typing import Any, Dict, List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class StepsTaskTypedDict(TypedDict):
    id: NotRequired[Nullable[str]]
    r"""A unique identifier for the task."""
    config: NotRequired[Nullable[Dict[str, Any]]]
    variables: NotRequired[Nullable[List[VariableTypedDict]]]
    metadata: NotRequired[Nullable[ContextTaskMetadataTypedDict]]
    tool: NotRequired[Nullable[ContextToolInfoTypedDict]]
    type: Literal["steps"]
    version: Literal["v1alpha"]
    steps: NotRequired[List[StepTypedDict]]


class StepsTask(BaseModel):
    id: OptionalNullable[str] = UNSET
    r"""A unique identifier for the task."""

    config: OptionalNullable[Dict[str, Any]] = UNSET

    variables: OptionalNullable[List[Variable]] = UNSET

    metadata: OptionalNullable[ContextTaskMetadata] = UNSET

    tool: OptionalNullable[ContextToolInfo] = UNSET

    TYPE: Annotated[
        Annotated[Optional[Literal["steps"]], AfterValidator(validate_const("steps"))],
        pydantic.Field(alias="type"),
    ] = "steps"

    VERSION: Annotated[
        Annotated[
            Optional[Literal["v1alpha"]], AfterValidator(validate_const("v1alpha"))
        ],
        pydantic.Field(alias="version"),
    ] = "v1alpha"

    steps: Optional[List[Step]] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "id",
                "config",
                "variables",
                "metadata",
                "tool",
                "type",
                "version",
                "steps",
            ]
        )
        nullable_fields = set(["id", "config", "variables", "metadata", "tool"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

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

        return m
