# 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 List, Optional

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

from mozart_api.models.latency_profile import LatencyProfile
from mozart_api.models.speaker_group_member import SpeakerGroupMember


class SpeakerGroup(BaseModel):
    """
    SpeakerGroup
    """

    crossover_frequency: Optional[conint(strict=True, le=300, ge=20)] = Field(
        default=None,
        alias="crossoverFrequency",
        description="Crossover frequency for bass management in Hz",
    )
    enable_phase_compensation: Optional[StrictBool] = Field(
        default=None,
        alias="enablePhaseCompensation",
        description="Enable phase compensation in bass management.",
    )
    friendly_name: Optional[StrictStr] = Field(
        default=None,
        alias="friendlyName",
        description="Friendly name of the SpeakerGroup. Required when creating a new group ",
    )
    id: Optional[StrictStr] = None
    is_deleteable: Optional[StrictBool] = Field(default=None, alias="isDeleteable")
    items: Optional[conlist(SpeakerGroupMember)] = None
    latency_profile: Optional[LatencyProfile] = Field(
        default=None, alias="latencyProfile"
    )
    room_compensation_id: Optional[StrictStr] = Field(
        default=None,
        alias="roomCompensationId",
        description="ID of the calculated coefficents for this group, made during advanced room compensation. When updating an existing group, an empty string will clear roomCompensationId. ",
    )
    speaker_preset: Optional[conint(strict=True, le=99, ge=0)] = Field(
        default=None,
        alias="speakerPreset",
        description="Speaker preset / listening mode eg. BL28 curtain position etc.",
    )
    __properties = [
        "crossoverFrequency",
        "enablePhaseCompensation",
        "friendlyName",
        "id",
        "isDeleteable",
        "items",
        "latencyProfile",
        "roomCompensationId",
        "speakerPreset",
    ]

    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) -> SpeakerGroup:
        """Create an instance of SpeakerGroup 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 each item in items (list)
        _items = []
        if self.items:
            for _item in self.items:
                if _item:
                    _items.append(_item.to_dict())
            _dict["items"] = _items
        # override the default output from pydantic by calling `to_dict()` of latency_profile
        if self.latency_profile:
            _dict["latencyProfile"] = self.latency_profile.to_dict()
        # set to None if crossover_frequency (nullable) is None
        # and __fields_set__ contains the field
        if (
            self.crossover_frequency is None
            and "crossover_frequency" in self.__fields_set__
        ):
            _dict["crossoverFrequency"] = None

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

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

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

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

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

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

        return _dict

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

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

        _obj = SpeakerGroup.parse_obj(
            {
                "crossover_frequency": obj.get("crossoverFrequency"),
                "enable_phase_compensation": obj.get("enablePhaseCompensation"),
                "friendly_name": obj.get("friendlyName"),
                "id": obj.get("id"),
                "is_deleteable": obj.get("isDeleteable"),
                "items": (
                    [SpeakerGroupMember.from_dict(_item) for _item in obj.get("items")]
                    if obj.get("items") is not None
                    else None
                ),
                "latency_profile": (
                    LatencyProfile.from_dict(obj.get("latencyProfile"))
                    if obj.get("latencyProfile") is not None
                    else None
                ),
                "room_compensation_id": obj.get("roomCompensationId"),
                "speaker_preset": obj.get("speakerPreset"),
            }
        )
        return _obj
