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

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

from mozart_api.models.play_queue_item_type import PlayQueueItemType
from mozart_api.models.playback_content_metadata import PlaybackContentMetadata


class PlayQueueItem(BaseModel):
    """
    PlayQueueItem
    """

    index: Optional[StrictInt] = None
    metadata: Optional[PlaybackContentMetadata] = None
    playlist_sort_by: Optional[StrictStr] = Field(
        default=None,
        alias="playlistSortBy",
        description="Option to choose the order that a playlist is sorted by",
    )
    provider: PlayQueueItemType = Field(...)
    start_now_from_position: Optional[StrictInt] = Field(
        default=None,
        alias="startNowFromPosition",
        description="Start playing specified track as soon as possible. This works for any type, for `track` set to 0 and for `playlist` specify the wanted track from position 0",
    )
    type: StrictStr = Field(...)
    uri: StrictStr = Field(
        default=...,
        description="This can be url, track id, playlist id, radio id and suchlike",
    )
    __properties = [
        "index",
        "metadata",
        "playlistSortBy",
        "provider",
        "startNowFromPosition",
        "type",
        "uri",
    ]

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

        if value not in (
            "name",
            "artist",
            "date",
            "album",
        ):
            raise ValueError(
                "must be one of enum values ('name', 'artist', 'date', 'album')"
            )
        return value

    @validator("type")
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in (
            "track",
            "playlist",
        ):
            raise ValueError("must be one of enum values ('track', 'playlist')")
        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) -> PlayQueueItem:
        """Create an instance of PlayQueueItem 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 metadata
        if self.metadata:
            _dict["metadata"] = self.metadata.to_dict()
        # override the default output from pydantic by calling `to_dict()` of provider
        if self.provider:
            _dict["provider"] = self.provider.to_dict()
        # set to None if playlist_sort_by (nullable) is None
        # and __fields_set__ contains the field
        if self.playlist_sort_by is None and "playlist_sort_by" in self.__fields_set__:
            _dict["playlistSortBy"] = None

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

        return _dict

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

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

        _obj = PlayQueueItem.parse_obj(
            {
                "index": obj.get("index"),
                "metadata": PlaybackContentMetadata.from_dict(obj.get("metadata"))
                if obj.get("metadata") is not None
                else None,
                "playlist_sort_by": obj.get("playlistSortBy"),
                "provider": PlayQueueItemType.from_dict(obj.get("provider"))
                if obj.get("provider") is not None
                else None,
                "start_now_from_position": obj.get("startNowFromPosition"),
                "type": obj.get("type"),
                "uri": obj.get("uri"),
            }
        )
        return _obj
