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

from __future__ import annotations
from .callaction import CallAction, CallActionTypedDict
from .incrementaction import IncrementAction, IncrementActionTypedDict
from .sayaction import SayAction, SayActionTypedDict
from .setvalueaction import SetValueAction, SetValueActionTypedDict
from pydantic import Discriminator, Tag, model_serializer
from syllable_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from syllable_sdk.utils import get_discriminator
from typing import List, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


EventTaskEventsStartTypedDict = TypeAliasType(
    "EventTaskEventsStartTypedDict",
    Union[
        IncrementActionTypedDict,
        SayActionTypedDict,
        SetValueActionTypedDict,
        CallActionTypedDict,
    ],
)


EventTaskEventsStart = Annotated[
    Union[
        Annotated[CallAction, Tag("call")],
        Annotated[IncrementAction, Tag("inc")],
        Annotated[SayAction, Tag("say")],
        Annotated[SetValueAction, Tag("set")],
    ],
    Discriminator(lambda m: get_discriminator(m, "action", "action")),
]


class EventTaskEventsTypedDict(TypedDict):
    start: NotRequired[Nullable[List[EventTaskEventsStartTypedDict]]]
    r"""Actions to execute on the first input from the user."""


class EventTaskEvents(BaseModel):
    start: OptionalNullable[List[EventTaskEventsStart]] = UNSET
    r"""Actions to execute on the first input from the user."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["start"])
        nullable_fields = set(["start"])
        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
