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

from __future__ import annotations
from .conditionaltext import ConditionalText, ConditionalTextTypedDict
from .inputparameter import InputParameter, InputParameterTypedDict
from .nextstep import NextStep, NextStepTypedDict
from .stepeventactions import StepEventActions, StepEventActionsTypedDict
from .steptools import StepTools, StepToolsTypedDict
from pydantic import model_serializer
from syllable_sdk.types import BaseModel, UNSET_SENTINEL
from typing import List, Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict


InstructionTypedDict = TypeAliasType(
    "InstructionTypedDict", Union[ConditionalTextTypedDict, str]
)


Instruction = TypeAliasType("Instruction", Union[ConditionalText, str])


NextTypedDict = TypeAliasType("NextTypedDict", Union[NextStepTypedDict, str])


Next = TypeAliasType("Next", Union[NextStep, str])


class StepTypedDict(TypedDict):
    id: str
    r"""The unique identifier of the step."""
    goal: str
    r"""The goal of the step."""
    instructions: NotRequired[List[InstructionTypedDict]]
    r"""The instructions for the step."""
    tools: NotRequired[StepToolsTypedDict]
    r"""Configuration for tools available in a step."""
    inputs: NotRequired[List[InputParameterTypedDict]]
    r"""The inputs for the step."""
    on: NotRequired[StepEventActionsTypedDict]
    r"""Actions to perform when events occur (enter, presubmit, submit)."""
    next: NotRequired[List[NextTypedDict]]
    r"""The next steps to execute."""


class Step(BaseModel):
    id: str
    r"""The unique identifier of the step."""

    goal: str
    r"""The goal of the step."""

    instructions: Optional[List[Instruction]] = None
    r"""The instructions for the step."""

    tools: Optional[StepTools] = None
    r"""Configuration for tools available in a step."""

    inputs: Optional[List[InputParameter]] = None
    r"""The inputs for the step."""

    on: Optional[StepEventActions] = None
    r"""Actions to perform when events occur (enter, presubmit, submit)."""

    next: Optional[List[Next]] = None
    r"""The next steps to execute."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["instructions", "tools", "inputs", "on", "next"])
        serialized = handler(self)
        m = {}

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

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

        return m
