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

from __future__ import annotations
from .workflowexecutionstartedattributesresponse import (
    WorkflowExecutionStartedAttributesResponse,
    WorkflowExecutionStartedAttributesResponseTypedDict,
)
from mistralai.client.types import BaseModel, Nullable, UNSET_SENTINEL
from mistralai.client.utils import validate_const
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from typing import Literal, Optional
from typing_extensions import Annotated, TypedDict


class WorkflowExecutionStartedResponseTypedDict(TypedDict):
    r"""Emitted when a workflow execution begins.

    This is the first event in any workflow execution lifecycle.
    """

    event_id: str
    r"""Unique identifier for this event instance."""
    event_timestamp: int
    r"""Unix timestamp in nanoseconds when the event was created."""
    root_workflow_exec_id: str
    r"""Execution ID of the root workflow that initiated this execution chain."""
    parent_workflow_exec_id: Nullable[str]
    r"""Execution ID of the parent workflow that initiated this execution. If this is a root workflow, this field is not set."""
    workflow_exec_id: str
    r"""Execution ID of the workflow that emitted this event."""
    workflow_run_id: str
    r"""Run ID of the workflow execution. Changes on continue-as-new while workflow_exec_id stays the same."""
    workflow_name: str
    r"""The registered name of the workflow that emitted this event."""
    attributes: WorkflowExecutionStartedAttributesResponseTypedDict
    r"""Attributes for workflow execution started events."""
    event_type: Literal["WORKFLOW_EXECUTION_STARTED"]
    r"""Event type discriminator."""


class WorkflowExecutionStartedResponse(BaseModel):
    r"""Emitted when a workflow execution begins.

    This is the first event in any workflow execution lifecycle.
    """

    event_id: str
    r"""Unique identifier for this event instance."""

    event_timestamp: int
    r"""Unix timestamp in nanoseconds when the event was created."""

    root_workflow_exec_id: str
    r"""Execution ID of the root workflow that initiated this execution chain."""

    parent_workflow_exec_id: Nullable[str]
    r"""Execution ID of the parent workflow that initiated this execution. If this is a root workflow, this field is not set."""

    workflow_exec_id: str
    r"""Execution ID of the workflow that emitted this event."""

    workflow_run_id: str
    r"""Run ID of the workflow execution. Changes on continue-as-new while workflow_exec_id stays the same."""

    workflow_name: str
    r"""The registered name of the workflow that emitted this event."""

    attributes: WorkflowExecutionStartedAttributesResponse
    r"""Attributes for workflow execution started events."""

    event_type: Annotated[
        Annotated[
            Optional[Literal["WORKFLOW_EXECUTION_STARTED"]],
            AfterValidator(validate_const("WORKFLOW_EXECUTION_STARTED")),
        ],
        pydantic.Field(alias="event_type"),
    ] = "WORKFLOW_EXECUTION_STARTED"
    r"""Event type discriminator."""

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


try:
    WorkflowExecutionStartedResponse.model_rebuild()
except NameError:
    pass
