from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..models.speech_req_model import SpeechReqModel
from ..models.speech_req_response_format import SpeechReqResponseFormat
from ..models.speech_req_voice import SpeechReqVoice
from ..types import UNSET, Unset

T = TypeVar("T", bound="SpeechReq")


@_attrs_define
class SpeechReq:
    """
    Attributes:
        input_ (str):
        model (SpeechReqModel | Unset):  Default: SpeechReqModel.TTS_1_HD.
        voice (SpeechReqVoice | Unset):  Default: SpeechReqVoice.ALLOY.
        response_format (SpeechReqResponseFormat | Unset):  Default: SpeechReqResponseFormat.MP3.
        speed (float | Unset):  Default: 1.0.
    """

    input_: str
    model: SpeechReqModel | Unset = SpeechReqModel.TTS_1_HD
    voice: SpeechReqVoice | Unset = SpeechReqVoice.ALLOY
    response_format: SpeechReqResponseFormat | Unset = SpeechReqResponseFormat.MP3
    speed: float | Unset = 1.0
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        input_ = self.input_

        model: str | Unset = UNSET
        if not isinstance(self.model, Unset):
            model = self.model.value

        voice: str | Unset = UNSET
        if not isinstance(self.voice, Unset):
            voice = self.voice.value

        response_format: str | Unset = UNSET
        if not isinstance(self.response_format, Unset):
            response_format = self.response_format.value

        speed = self.speed

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "input": input_,
            }
        )
        if model is not UNSET:
            field_dict["model"] = model
        if voice is not UNSET:
            field_dict["voice"] = voice
        if response_format is not UNSET:
            field_dict["response_format"] = response_format
        if speed is not UNSET:
            field_dict["speed"] = speed

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        input_ = d.pop("input")

        _model = d.pop("model", UNSET)
        model: SpeechReqModel | Unset
        if isinstance(_model, Unset):
            model = UNSET
        else:
            model = SpeechReqModel(_model)

        _voice = d.pop("voice", UNSET)
        voice: SpeechReqVoice | Unset
        if isinstance(_voice, Unset):
            voice = UNSET
        else:
            voice = SpeechReqVoice(_voice)

        _response_format = d.pop("response_format", UNSET)
        response_format: SpeechReqResponseFormat | Unset
        if isinstance(_response_format, Unset):
            response_format = UNSET
        else:
            response_format = SpeechReqResponseFormat(_response_format)

        speed = d.pop("speed", UNSET)

        speech_req = cls(
            input_=input_,
            model=model,
            voice=voice,
            response_format=response_format,
            speed=speed,
        )

        speech_req.additional_properties = d
        return speech_req

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
