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

import datetime as dt
import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from .conversation_agent import ConversationAgent
from .conversation_background_noise import ConversationBackgroundNoise
from .conversation_ended_by import ConversationEndedBy
from .conversation_item import ConversationItem
from .conversation_project import ConversationProject


class Conversation(UniversalBaseModel):
    id: str = pydantic.Field()
    """
    The conversation ID.
    """

    agent: typing.Optional[ConversationAgent] = pydantic.Field(default=None)
    """
    The agent associated with the conversation.
    """

    workspace: str = pydantic.Field()
    """
    The organization/workspace name.
    """

    project: ConversationProject = pydantic.Field()
    """
    The project associated with the conversation.
    """

    external_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    External ID for conversation tracking.
    """

    model: str = pydantic.Field()
    """
    The STS model used.
    """

    welcome_message: typing.Optional[str] = pydantic.Field(default=None)
    """
    Welcome message played at start.
    """

    template_variables: typing.Dict[str, str] = pydantic.Field()
    """
    Template variables used in the conversation.
    """

    input_format: str = pydantic.Field()
    """
    Audio input format.
    """

    output_format: str = pydantic.Field()
    """
    Audio output format.
    """

    background_noise_level: float = pydantic.Field()
    """
    Background noise level used in the conversation.
    """

    background_noise: typing.Optional[ConversationBackgroundNoise] = pydantic.Field(default=None)
    """
    The background noise type used in the conversation.
    """

    live_transcript: str = pydantic.Field()
    """
    Live transcript of the conversation.
    """

    post_call_transcript: typing.Optional[str] = pydantic.Field(default=None)
    """
    Post-call processed transcript.
    """

    duration_ms: float = pydantic.Field()
    """
    Duration of the conversation in milliseconds.
    """

    audio_url: typing.Optional[str] = pydantic.Field(default=None)
    """
    Presigned URL to the conversation audio file.
    """

    started_at: dt.datetime = pydantic.Field()
    """
    When the conversation started.
    """

    ended_at: typing.Optional[dt.datetime] = pydantic.Field(default=None)
    """
    When the conversation ended.
    """

    ended_by: typing.Optional[ConversationEndedBy] = pydantic.Field(default=None)
    """
    Who or what ended the conversation.
    """

    boosted_keywords: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    These words, or short phrases, are more accurately recognized by the model.
    """

    languages: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Array of ISO 639-1 language codes recognized by the model.
    """

    no_input_poke_sec: typing.Optional[int] = pydantic.Field(default=None)
    """
    Number of seconds of silence before a poke message is sent. `null` means the poke message is disabled.
    """

    no_input_poke_text: typing.Optional[str] = pydantic.Field(default=None)
    """
    The message to send after the specified silence. Relevant only if `no_input_poke_sec` is not `null`.
    """

    no_input_end_conversation_sec: typing.Optional[int] = pydantic.Field(default=None)
    """
    Seconds of silence before the conversation is ended.
    """

    task_results: typing.Dict[str, typing.Optional[typing.Any]] = pydantic.Field()
    """
    Results from conversation evaluations and extractions.
    """

    items: typing.List[ConversationItem] = pydantic.Field()
    """
    Array of conversation items (turns).
    """

    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
