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

from __future__ import annotations
from .workflowexecutioncontinuedasnewattributesresponse import (
    WorkflowExecutionContinuedAsNewAttributesResponse,
    WorkflowExecutionContinuedAsNewAttributesResponseTypedDict,
)
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 WorkflowExecutionContinuedAsNewResponseTypedDict(TypedDict):
    r"""Emitted when a workflow continues as a new execution.

    This occurs when a workflow uses continue-as-new to reset its history
    while maintaining logical continuity.
    """

    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: WorkflowExecutionContinuedAsNewAttributesResponseTypedDict
    r"""Attributes for workflow execution continued-as-new events."""
    event_type: Literal["WORKFLOW_EXECUTION_CONTINUED_AS_NEW"]
    r"""Event type discriminator."""


class WorkflowExecutionContinuedAsNewResponse(BaseModel):
    r"""Emitted when a workflow continues as a new execution.

    This occurs when a workflow uses continue-as-new to reset its history
    while maintaining logical continuity.
    """

    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: WorkflowExecutionContinuedAsNewAttributesResponse
    r"""Attributes for workflow execution continued-as-new events."""

    event_type: Annotated[
        Annotated[
            Optional[Literal["WORKFLOW_EXECUTION_CONTINUED_AS_NEW"]],
            AfterValidator(validate_const("WORKFLOW_EXECUTION_CONTINUED_AS_NEW")),
        ],
        pydantic.Field(alias="event_type"),
    ] = "WORKFLOW_EXECUTION_CONTINUED_AS_NEW"
    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:
    WorkflowExecutionContinuedAsNewResponse.model_rebuild()
except NameError:
    pass
