# coding: utf-8

"""
    Mozart platform API

    API for interacting with the Mozart platform.

    The version of the OpenAPI document: 0.2.0
    Contact: support@bang-olufsen.dk
    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 typing import Optional

try:
    from pydantic.v1 import BaseModel, Field, conint
except ImportError:
    from pydantic import BaseModel, Field, conint

from mozart_api.models.overlay_play_request_from_usb_from_usb import (
    OverlayPlayRequestFromUsbFromUsb,
)
from mozart_api.models.overlay_play_request_text_to_speech_text_to_speech import (
    OverlayPlayRequestTextToSpeechTextToSpeech,
)
from mozart_api.models.uri import Uri


class OverlayPlayRequest(BaseModel):
    """
    OverlayPlayRequest
    """

    volume_absolute: Optional[conint(strict=True, le=100, ge=0)] = Field(
        default=None,
        alias="volumeAbsolute",
        description="An optional absolute volume level at which to play the URI. If not provided, the URI will play at the currently configured volume level on the product. The level should be provided in volume steps [0, 100] ",
    )
    uri: Optional[Uri] = None
    text_to_speech: Optional[OverlayPlayRequestTextToSpeechTextToSpeech] = Field(
        default=None, alias="textToSpeech"
    )
    from_usb: Optional[OverlayPlayRequestFromUsbFromUsb] = Field(
        default=None, alias="fromUsb"
    )
    __properties = ["volumeAbsolute", "uri", "textToSpeech", "fromUsb"]

    class Config:
        """Pydantic configuration"""

        allow_population_by_field_name = True
        validate_assignment = True

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

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

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

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True, exclude={}, exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of uri
        if self.uri:
            _dict["uri"] = self.uri.to_dict()
        # override the default output from pydantic by calling `to_dict()` of text_to_speech
        if self.text_to_speech:
            _dict["textToSpeech"] = self.text_to_speech.to_dict()
        # override the default output from pydantic by calling `to_dict()` of from_usb
        if self.from_usb:
            _dict["fromUsb"] = self.from_usb.to_dict()
        # set to None if volume_absolute (nullable) is None
        # and __fields_set__ contains the field
        if self.volume_absolute is None and "volume_absolute" in self.__fields_set__:
            _dict["volumeAbsolute"] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> OverlayPlayRequest:
        """Create an instance of OverlayPlayRequest from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return OverlayPlayRequest.parse_obj(obj)

        _obj = OverlayPlayRequest.parse_obj(
            {
                "volume_absolute": obj.get("volumeAbsolute"),
                "uri": (
                    Uri.from_dict(obj.get("uri"))
                    if obj.get("uri") is not None
                    else None
                ),
                "text_to_speech": (
                    OverlayPlayRequestTextToSpeechTextToSpeech.from_dict(
                        obj.get("textToSpeech")
                    )
                    if obj.get("textToSpeech") is not None
                    else None
                ),
                "from_usb": (
                    OverlayPlayRequestFromUsbFromUsb.from_dict(obj.get("fromUsb"))
                    if obj.get("fromUsb") is not None
                    else None
                ),
            }
        )
        return _obj
