"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from pydantic import model_serializer
from syllable_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from typing_extensions import NotRequired, TypedDict


class TelephonyConfigurationsTypedDict(TypedDict):
    pre_input_timeout: NotRequired[Nullable[float]]
    r"""Pre input silence threshold"""
    post_speech_input_timeout: NotRequired[Nullable[float]]
    r"""Post speech silence timeout to determine input as ended."""
    post_dtmf_input_timeout: NotRequired[Nullable[float]]
    r"""Post dtmf silence timeout to determine input as ended."""
    overall_input_timeout: NotRequired[Nullable[float]]
    r"""Total input timeout"""
    output_padding: NotRequired[Nullable[float]]
    r"""Number of seconds to start listening to user input before assistant speech ends"""
    interruptibility: NotRequired[Nullable[str]]
    r"""Interruptibility setting for user input.Valid values: none, dtmf_only, speech_only, all"""
    passive_speech_input_enabled: NotRequired[Nullable[bool]]
    r"""Whether passive speech input is enabled (input while assistant is speaking)"""
    passive_input_start: NotRequired[Nullable[float]]
    r"""Waiting time to start passive input (in seconds) after start of assistant speech"""
    async_enabled: NotRequired[Nullable[bool]]
    r"""Whether asynchronous mode is enabled for the conversation"""


class TelephonyConfigurations(BaseModel):
    pre_input_timeout: OptionalNullable[float] = UNSET
    r"""Pre input silence threshold"""

    post_speech_input_timeout: OptionalNullable[float] = UNSET
    r"""Post speech silence timeout to determine input as ended."""

    post_dtmf_input_timeout: OptionalNullable[float] = UNSET
    r"""Post dtmf silence timeout to determine input as ended."""

    overall_input_timeout: OptionalNullable[float] = UNSET
    r"""Total input timeout"""

    output_padding: OptionalNullable[float] = UNSET
    r"""Number of seconds to start listening to user input before assistant speech ends"""

    interruptibility: OptionalNullable[str] = UNSET
    r"""Interruptibility setting for user input.Valid values: none, dtmf_only, speech_only, all"""

    passive_speech_input_enabled: OptionalNullable[bool] = UNSET
    r"""Whether passive speech input is enabled (input while assistant is speaking)"""

    passive_input_start: OptionalNullable[float] = UNSET
    r"""Waiting time to start passive input (in seconds) after start of assistant speech"""

    async_enabled: OptionalNullable[bool] = UNSET
    r"""Whether asynchronous mode is enabled for the conversation"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "pre_input_timeout",
                "post_speech_input_timeout",
                "post_dtmf_input_timeout",
                "overall_input_timeout",
                "output_padding",
                "interruptibility",
                "passive_speech_input_enabled",
                "passive_input_start",
                "async_enabled",
            ]
        )
        nullable_fields = set(
            [
                "pre_input_timeout",
                "post_speech_input_timeout",
                "post_dtmf_input_timeout",
                "overall_input_timeout",
                "output_padding",
                "interruptibility",
                "passive_speech_input_enabled",
                "passive_input_start",
                "async_enabled",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            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
