# coding: utf-8

"""
    Jellyfin API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 10.11.0
    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt
from typing import Any, ClassVar, Dict, List, Optional
from openapi_client.models.group_repeat_mode import GroupRepeatMode
from openapi_client.models.group_shuffle_mode import GroupShuffleMode
from openapi_client.models.play_queue_update_reason import PlayQueueUpdateReason
from openapi_client.models.sync_play_queue_item import SyncPlayQueueItem
from typing import Optional, Set
from typing_extensions import Self

class PlayQueueUpdate(BaseModel):
    """
    Class PlayQueueUpdate.
    """ # noqa: E501
    reason: Optional[PlayQueueUpdateReason] = Field(default=None, description="Gets the request type that originated this update.", alias="Reason")
    last_update: Optional[datetime] = Field(default=None, description="Gets the UTC time of the last change to the playing queue.", alias="LastUpdate")
    playlist: Optional[List[SyncPlayQueueItem]] = Field(default=None, description="Gets the playlist.", alias="Playlist")
    playing_item_index: Optional[StrictInt] = Field(default=None, description="Gets the playing item index in the playlist.", alias="PlayingItemIndex")
    start_position_ticks: Optional[StrictInt] = Field(default=None, description="Gets the start position ticks.", alias="StartPositionTicks")
    is_playing: Optional[StrictBool] = Field(default=None, description="Gets a value indicating whether the current item is playing.", alias="IsPlaying")
    shuffle_mode: Optional[GroupShuffleMode] = Field(default=None, description="Gets the shuffle mode.", alias="ShuffleMode")
    repeat_mode: Optional[GroupRepeatMode] = Field(default=None, description="Gets the repeat mode.", alias="RepeatMode")
    __properties: ClassVar[List[str]] = ["Reason", "LastUpdate", "Playlist", "PlayingItemIndex", "StartPositionTicks", "IsPlaying", "ShuffleMode", "RepeatMode"]

    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 PlayQueueUpdate 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 each item in playlist (list)
        _items = []
        if self.playlist:
            for _item_playlist in self.playlist:
                if _item_playlist:
                    _items.append(_item_playlist.to_dict())
            _dict['Playlist'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "Reason": obj.get("Reason"),
            "LastUpdate": obj.get("LastUpdate"),
            "Playlist": [SyncPlayQueueItem.from_dict(_item) for _item in obj["Playlist"]] if obj.get("Playlist") is not None else None,
            "PlayingItemIndex": obj.get("PlayingItemIndex"),
            "StartPositionTicks": obj.get("StartPositionTicks"),
            "IsPlaying": obj.get("IsPlaying"),
            "ShuffleMode": obj.get("ShuffleMode"),
            "RepeatMode": obj.get("RepeatMode")
        })
        return _obj


