# coding: utf-8

"""
    VoiceOS

    VoiceOS API

    The version of the OpenAPI document: 0.8.0
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from voiceos.models.eleven_labs_model import ElevenLabsModel
from voiceos.models.voice_id import VoiceId
from typing import Optional, Set
from typing_extensions import Self

class ElevenlabsVoice(BaseModel):
    """
    ElevenlabsVoice
    """ # noqa: E501
    provider: Optional[StrictStr] = Field(default='elevenlabs', description="The voice provider.")
    voice_id: Optional[VoiceId] = None
    model_id: Optional[ElevenLabsModel] = Field(default=None, description="The model to use. Defaults to eleven_turbo_v2.")
    optimize_latency: Optional[Annotated[int, Field(le=4, strict=True, ge=0)]] = Field(default=3, description="Optimize for latency.")
    use_speaker_boost: Optional[StrictBool] = Field(default=False, description="Use speaker boost.")
    similarity_boost: Optional[Annotated[int, Field(le=1, strict=True, ge=0)]] = Field(default=0.5, description="Boost the similarity of the generated audio to the input text.")
    stability: Optional[Annotated[int, Field(le=1, strict=True, ge=0)]] = Field(default=0.5, description="Control the stability of the generated audio.")
    __properties: ClassVar[List[str]] = ["provider", "voice_id", "model_id", "optimize_latency", "use_speaker_boost", "similarity_boost", "stability"]

    @field_validator('provider')
    def provider_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['elevenlabs']):
            raise ValueError("must be one of enum values ('elevenlabs')")
        return value

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of ElevenlabsVoice from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of voice_id
        if self.voice_id:
            _dict['voice_id'] = self.voice_id.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ElevenlabsVoice from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "provider": obj.get("provider") if obj.get("provider") is not None else 'elevenlabs',
            "voice_id": VoiceId.from_dict(obj["voice_id"]) if obj.get("voice_id") is not None else None,
            "model_id": obj.get("model_id"),
            "optimize_latency": obj.get("optimize_latency") if obj.get("optimize_latency") is not None else 3,
            "use_speaker_boost": obj.get("use_speaker_boost") if obj.get("use_speaker_boost") is not None else False,
            "similarity_boost": obj.get("similarity_boost") if obj.get("similarity_boost") is not None else 0.5,
            "stability": obj.get("stability") if obj.get("stability") is not None else 0.5
        })
        return _obj


