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

from __future__ import annotations
from .metadatadict import MetadataDict, MetadataDictTypedDict
from .speechoutputformat import SpeechOutputFormat
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import ConfigDict, model_serializer
from typing import Any, Dict, Optional
from typing_extensions import NotRequired, TypedDict


class SpeechRequestTypedDict(TypedDict):
    input: str
    r"""Text to generate a speech from"""
    model: NotRequired[Nullable[str]]
    metadata: NotRequired[Nullable[MetadataDictTypedDict]]
    stream: NotRequired[bool]
    voice_id: NotRequired[Nullable[str]]
    r"""The preset or custom voice to use for generating the speech."""
    ref_audio: NotRequired[Nullable[str]]
    r"""The audio reference for generating the speech."""
    response_format: NotRequired[SpeechOutputFormat]


class SpeechRequest(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True, arbitrary_types_allowed=True, extra="allow"
    )
    __pydantic_extra__: Dict[str, Any] = pydantic.Field(init=False)

    input: str
    r"""Text to generate a speech from"""

    model: OptionalNullable[str] = UNSET

    metadata: OptionalNullable[MetadataDict] = UNSET

    stream: Optional[bool] = False

    voice_id: OptionalNullable[str] = UNSET
    r"""The preset or custom voice to use for generating the speech."""

    ref_audio: OptionalNullable[str] = UNSET
    r"""The audio reference for generating the speech."""

    response_format: Optional[SpeechOutputFormat] = None

    @property
    def additional_properties(self):
        return self.__pydantic_extra__

    @additional_properties.setter
    def additional_properties(self, value):
        self.__pydantic_extra__ = value  # pyright: ignore[reportIncompatibleVariableOverride]

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["model", "metadata", "stream", "voice_id", "ref_audio", "response_format"]
        )
        nullable_fields = set(["model", "metadata", "voice_id", "ref_audio"])
        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))
            serialized.pop(k, serialized.pop(n, None))
            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
        for k, v in serialized.items():
            m[k] = v

        return m
