# 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 json
import pprint
import re  # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional, Set, Union

from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing_extensions import Annotated, Self

from mozart_api.models.speaker_group_member_location import SpeakerGroupMemberLocation


class SpeakerGroupMember(BaseModel):
    """
    SpeakerGroupMember
    """  # noqa: E501

    distance: Annotated[
        Optional[Annotated[int, Field(le=1500, strict=True, ge=0)]],
        Field(description="Distance from listening position in cm"),
    ] = None
    friendly_name: Annotated[Optional[StrictStr], Field(alias="friendlyName")] = None
    gain: Annotated[
        Optional[
            Union[
                Annotated[float, Field(le=6, strict=True, ge=-24)],
                Annotated[int, Field(le=6, strict=True, ge=-24)],
            ]
        ],
        Field(description="Level in dB"),
    ] = None
    id: StrictStr
    location: Optional[SpeakerGroupMemberLocation] = None
    redirection_level: Annotated[
        Optional[Annotated[int, Field(le=6, strict=True, ge=-100)]],
        Field(
            description="Redirection level for bass management in dB",
            alias="redirectionLevel",
        ),
    ] = None
    role: Optional[StrictStr] = None
    type: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = [
        "distance",
        "friendlyName",
        "gain",
        "id",
        "location",
        "redirectionLevel",
        "role",
        "type",
    ]

    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 SpeakerGroupMember 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 location
        if self.location:
            _dict["location"] = self.location.to_dict()
        # set to None if distance (nullable) is None
        # and model_fields_set contains the field
        if self.distance is None and "distance" in self.model_fields_set:
            _dict["distance"] = None

        # set to None if friendly_name (nullable) is None
        # and model_fields_set contains the field
        if self.friendly_name is None and "friendly_name" in self.model_fields_set:
            _dict["friendlyName"] = None

        # set to None if gain (nullable) is None
        # and model_fields_set contains the field
        if self.gain is None and "gain" in self.model_fields_set:
            _dict["gain"] = None

        # set to None if location (nullable) is None
        # and model_fields_set contains the field
        if self.location is None and "location" in self.model_fields_set:
            _dict["location"] = None

        # set to None if redirection_level (nullable) is None
        # and model_fields_set contains the field
        if (
            self.redirection_level is None
            and "redirection_level" in self.model_fields_set
        ):
            _dict["redirectionLevel"] = None

        # set to None if role (nullable) is None
        # and model_fields_set contains the field
        if self.role is None and "role" in self.model_fields_set:
            _dict["role"] = None

        # set to None if type (nullable) is None
        # and model_fields_set contains the field
        if self.type is None and "type" in self.model_fields_set:
            _dict["type"] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "distance": obj.get("distance"),
            "friendlyName": obj.get("friendlyName"),
            "gain": obj.get("gain"),
            "id": obj.get("id"),
            "location": SpeakerGroupMemberLocation.from_dict(obj["location"])
            if obj.get("location") is not None
            else None,
            "redirectionLevel": obj.get("redirectionLevel"),
            "role": obj.get("role"),
            "type": obj.get("type"),
        })
        return _obj
