"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: 36fd5b898ddd

from __future__ import annotations
from .querydefinition import QueryDefinition, QueryDefinitionTypedDict
from .signaldefinition import SignalDefinition, SignalDefinitionTypedDict
from .updatedefinition import UpdateDefinition, UpdateDefinitionTypedDict
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Any, Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class WorkflowCodeDefinitionTypedDict(TypedDict):
    input_schema: Dict[str, Any]
    r"""Input schema of the workflow's run method"""
    output_schema: NotRequired[Nullable[Dict[str, Any]]]
    r"""Output schema of the workflow's run method"""
    signals: NotRequired[List[SignalDefinitionTypedDict]]
    r"""Signal handlers defined by the workflow"""
    queries: NotRequired[List[QueryDefinitionTypedDict]]
    r"""Query handlers defined by the workflow"""
    updates: NotRequired[List[UpdateDefinitionTypedDict]]
    r"""Update handlers defined by the workflow"""
    enforce_determinism: NotRequired[bool]
    r"""Whether the workflow enforces deterministic execution"""
    execution_timeout: NotRequired[float]
    r"""Maximum total execution time including retries and continue-as-new"""
    plugin_metadata: NotRequired[Nullable[Dict[str, Any]]]
    r"""Plugin-specific metadata (e.g. connector declarations)"""


class WorkflowCodeDefinition(BaseModel):
    input_schema: Dict[str, Any]
    r"""Input schema of the workflow's run method"""

    output_schema: OptionalNullable[Dict[str, Any]] = UNSET
    r"""Output schema of the workflow's run method"""

    signals: Optional[List[SignalDefinition]] = None
    r"""Signal handlers defined by the workflow"""

    queries: Optional[List[QueryDefinition]] = None
    r"""Query handlers defined by the workflow"""

    updates: Optional[List[UpdateDefinition]] = None
    r"""Update handlers defined by the workflow"""

    enforce_determinism: Optional[bool] = False
    r"""Whether the workflow enforces deterministic execution"""

    execution_timeout: Optional[float] = None
    r"""Maximum total execution time including retries and continue-as-new"""

    plugin_metadata: OptionalNullable[Dict[str, Any]] = UNSET
    r"""Plugin-specific metadata (e.g. connector declarations)"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "output_schema",
                "signals",
                "queries",
                "updates",
                "enforce_determinism",
                "execution_timeout",
                "plugin_metadata",
            ]
        )
        nullable_fields = set(["output_schema", "plugin_metadata"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))
            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
