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

try:
    from pydantic.v1 import BaseModel, Field, StrictStr, conlist, constr, validator
except ImportError:
    from pydantic import BaseModel, Field, StrictStr, conlist, constr, validator

from mozart_api.models.action import Action


class Scene(BaseModel):
    """
    Scene
    """

    action_list: conlist(Action) = Field(
        default=...,
        alias="actionList",
        description="An ordered list of Actions to run on the product",
    )
    client_context: Optional[constr(strict=True, max_length=4096)] = Field(
        default=None,
        alias="clientContext",
        description="An optional generic string property supplied from the client. If supplied it will overwrite any currently stored clientContext. If not supplied any stored clientContext will be left unchanged. ",
    )
    label: Optional[StrictStr] = None
    tags: Optional[conlist(StrictStr)] = Field(
        default=None,
        description="A list of user defined tags. This allows a client to create virtual lists",
    )
    classification: Optional[StrictStr] = Field(
        default=None, description="The classification of Scene"
    )
    __properties = ["actionList", "clientContext", "label", "tags", "classification"]

    @validator("classification")
    def classification_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in (
            "system",
            "userDefined",
        ):
            raise ValueError("must be one of enum values ('system', 'userDefined')")
        return value

    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) -> Scene:
        """Create an instance of Scene 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 action_list (list)
        _items = []
        if self.action_list:
            for _item in self.action_list:
                if _item:
                    _items.append(_item.to_dict())
            _dict["actionList"] = _items
        # set to None if client_context (nullable) is None
        # and __fields_set__ contains the field
        if self.client_context is None and "client_context" in self.__fields_set__:
            _dict["clientContext"] = None

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

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

        return _dict

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

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

        _obj = Scene.parse_obj(
            {
                "action_list": [
                    Action.from_dict(_item) for _item in obj.get("actionList")
                ]
                if obj.get("actionList") is not None
                else None,
                "client_context": obj.get("clientContext"),
                "label": obj.get("label"),
                "tags": obj.get("tags"),
                "classification": obj.get("classification"),
            }
        )
        return _obj
