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

from __future__ import annotations
from .eventsource import EventSource
from .streameventssepayload import StreamEventSsePayload, StreamEventSsePayloadTypedDict
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from mistralai.client.utils import FieldMetadata, PathParamMetadata, QueryParamMetadata
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class StreamV1WorkflowsExecutionsExecutionIDStreamGetRequestTypedDict(TypedDict):
    execution_id: str
    event_source: NotRequired[Nullable[EventSource]]
    last_event_id: NotRequired[Nullable[str]]


class StreamV1WorkflowsExecutionsExecutionIDStreamGetRequest(BaseModel):
    execution_id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]

    event_source: Annotated[
        OptionalNullable[EventSource],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET

    last_event_id: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET

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


class StreamV1WorkflowsExecutionsExecutionIDStreamGetResponseBodyTypedDict(TypedDict):
    r"""Stream of Server-Sent Events (SSE)"""

    event: NotRequired[str]
    data: NotRequired[StreamEventSsePayloadTypedDict]
    id: NotRequired[str]
    retry: NotRequired[int]


class StreamV1WorkflowsExecutionsExecutionIDStreamGetResponseBody(BaseModel):
    r"""Stream of Server-Sent Events (SSE)"""

    event: Optional[str] = None

    data: Optional[StreamEventSsePayload] = None

    id: Optional[str] = None

    retry: Optional[int] = None

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

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

        return m
