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

from __future__ import annotations
from .speechstreamaudiodelta import (
    SpeechStreamAudioDelta,
    SpeechStreamAudioDeltaTypedDict,
)
from .speechstreamdone import SpeechStreamDone, SpeechStreamDoneTypedDict
from .speechstreameventtypes import SpeechStreamEventTypes
from functools import partial
from mistralai.client.types import BaseModel
from mistralai.client.utils import eventstreaming
from mistralai.client.utils.unions import parse_open_union
from pydantic import ConfigDict
from pydantic.functional_validators import BeforeValidator
from typing import Any, Literal, Union
from typing_extensions import Annotated, TypeAliasType, TypedDict


SpeechV1AudioSpeechPostDataTypedDict = TypeAliasType(
    "SpeechV1AudioSpeechPostDataTypedDict",
    Union[SpeechStreamAudioDeltaTypedDict, SpeechStreamDoneTypedDict],
)


class UnknownSpeechV1AudioSpeechPostData(BaseModel):
    r"""A SpeechV1AudioSpeechPostData variant the SDK doesn't recognize. Preserves the raw payload."""

    type: Literal["UNKNOWN"] = "UNKNOWN"
    raw: Any
    is_unknown: Literal[True] = True

    model_config = ConfigDict(frozen=True)


_SPEECH_V1_AUDIO_SPEECH_POST_DATA_VARIANTS: dict[str, Any] = {
    "speech.audio.delta": SpeechStreamAudioDelta,
    "speech.audio.done": SpeechStreamDone,
}


SpeechV1AudioSpeechPostData = Annotated[
    Union[SpeechStreamAudioDelta, SpeechStreamDone, UnknownSpeechV1AudioSpeechPostData],
    BeforeValidator(
        partial(
            parse_open_union,
            disc_key="type",
            variants=_SPEECH_V1_AUDIO_SPEECH_POST_DATA_VARIANTS,
            unknown_cls=UnknownSpeechV1AudioSpeechPostData,
            union_name="SpeechV1AudioSpeechPostData",
        )
    ),
]


class SpeechStreamEventsTypedDict(TypedDict):
    r"""Speech audio data."""

    event: SpeechStreamEventTypes
    data: SpeechV1AudioSpeechPostDataTypedDict


class SpeechStreamEvents(BaseModel):
    r"""Speech audio data."""

    event: SpeechStreamEventTypes

    data: SpeechV1AudioSpeechPostData


class SpeechResponseTypedDict(TypedDict):
    r"""Speech audio data."""

    audio_data: str
    r"""Base64 encoded audio data"""


class SpeechResponse(BaseModel):
    r"""Speech audio data."""

    audio_data: str
    r"""Base64 encoded audio data"""


SpeechV1AudioSpeechPostResponseTypedDict = TypeAliasType(
    "SpeechV1AudioSpeechPostResponseTypedDict",
    Union[
        SpeechResponseTypedDict,
        Union[
            eventstreaming.EventStream[SpeechStreamEventsTypedDict],
            eventstreaming.EventStreamAsync[SpeechStreamEventsTypedDict],
        ],
    ],
)


SpeechV1AudioSpeechPostResponse = TypeAliasType(
    "SpeechV1AudioSpeechPostResponse",
    Union[
        SpeechResponse,
        Union[
            eventstreaming.EventStream[SpeechStreamEvents],
            eventstreaming.EventStreamAsync[SpeechStreamEvents],
        ],
    ],
)
