from __future__ import annotations

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

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

from ..models.translation_req_response_format import TranslationReqResponseFormat
from ..types import UNSET, Unset

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


@_attrs_define
class TranslationReq:
    """
    Attributes:
        file_url (None | str | Unset):
        model (Literal['whisper-1'] | Unset):  Default: 'whisper-1'.
        prompt (str | Unset):  Default: ''.
        response_format (TranslationReqResponseFormat | Unset):  Default: TranslationReqResponseFormat.JSON.
        temperature (float | Unset):  Default: 0.2.
    """

    file_url: None | str | Unset = UNSET
    model: Literal["whisper-1"] | Unset = "whisper-1"
    prompt: str | Unset = ""
    response_format: TranslationReqResponseFormat | Unset = TranslationReqResponseFormat.JSON
    temperature: float | Unset = 0.2
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        file_url: None | str | Unset
        if isinstance(self.file_url, Unset):
            file_url = UNSET
        else:
            file_url = self.file_url

        model = self.model

        prompt = self.prompt

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

        temperature = self.temperature

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if file_url is not UNSET:
            field_dict["file_url"] = file_url
        if model is not UNSET:
            field_dict["model"] = model
        if prompt is not UNSET:
            field_dict["prompt"] = prompt
        if response_format is not UNSET:
            field_dict["response_format"] = response_format
        if temperature is not UNSET:
            field_dict["temperature"] = temperature

        return field_dict

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

        def _parse_file_url(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        file_url = _parse_file_url(d.pop("file_url", UNSET))

        model = cast(Literal["whisper-1"] | Unset, d.pop("model", UNSET))
        if model != "whisper-1" and not isinstance(model, Unset):
            raise ValueError(f"model must match const 'whisper-1', got '{model}'")

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

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

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

        translation_req = cls(
            file_url=file_url,
            model=model,
            prompt=prompt,
            response_format=response_format,
            temperature=temperature,
        )

        translation_req.additional_properties = d
        return translation_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
