# This file was auto-generated by Fern from our API Definition.

import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2
from ..core.unchecked_base_model import UncheckedBaseModel
from .pronunciation_dictionary_locator import PronunciationDictionaryLocator
from .text_to_dialogue_websocket_voice_input import TextToDialogueWebsocketVoiceInput
from .text_to_dialogue_websocket_voice_settings import TextToDialogueWebsocketVoiceSettings


class TextToDialogueWebsocketClientMessageMulti(UncheckedBaseModel):
    """
    All fields are optional unless noted for a context's **first** message.

    **Every message**
    - `context_id` is required, except on a message containing only `close_socket`.

    **First message for a context**
    - `voices`: non-empty array of voice IDs (maximum 10 per context for `eleven_v3`; exactly 1 for `eleven_v3_conversational`).
    - Credentials if not supplied via `xi-api-key` / `Authorization` headers or `single_use_token` query parameter (accepted on the first message of the connection only).

    **Subsequent messages for a context**
    - Do not resend `voices`, `voice_settings`, `pronunciation_dictionary_locators`, or credential fields.
    """

    context_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    Identifier for an independent dialogue stream within the socket. The first message with a new `context_id` creates that context. Required on every message except one containing only `close_socket`.
    """

    inputs: typing.Optional[typing.List[TextToDialogueWebsocketVoiceInput]] = pydantic.Field(default=None)
    """
    Dialogue lines to append to this context for synthesis. Each `voice_id` must be registered for this context.
    """

    flush: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Force generation of this context's buffered text without closing it.
    """

    close_context: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Flush this context's remaining audio, emit its `is_final` message, and close it. Other contexts stay open.
    """

    close_socket: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Flush all contexts, emit their remaining audio and `is_final` messages, and close the WebSocket.
    """

    keep_alive: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Resets this context's 20s inactivity timer; performs no synthesis.
    """

    xi_api_key: typing.Optional[str] = pydantic.Field(default=None)
    """
    API key for the first message of the connection if not provided via the `xi-api-key` header.
    """

    authorization: typing.Optional[str] = pydantic.Field(default=None)
    """
    Bearer token for the first message of the connection if not provided via the `Authorization` header.
    """

    single_use_token: typing.Optional[str] = pydantic.Field(default=None)
    """
    Single-use token for the first message of the connection if not provided via the `single_use_token` query parameter.
    """

    voices: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Voice IDs to load for this context (first message for the context only, required on that message).
    """

    voice_settings: typing.Optional[TextToDialogueWebsocketVoiceSettings] = pydantic.Field(default=None)
    """
    Optional voice settings for this context (first message for the context only).
    """

    pronunciation_dictionary_locators: typing.Optional[typing.List[PronunciationDictionaryLocator]] = pydantic.Field(
        default=None
    )
    """
    Optional pronunciation dictionaries for this context (first message for the context only).
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
