# coding: utf-8

"""
    YouTube Data API v3

    The YouTube Data API v3 is an API that provides access to YouTube data, such as videos, playlists, and channels.

    The version of the OpenAPI document: v3
    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 pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from youtube_ti.models.playlist_item_content_details import PlaylistItemContentDetails
from youtube_ti.models.playlist_item_snippet import PlaylistItemSnippet
from youtube_ti.models.playlist_item_status import PlaylistItemStatus
from typing import Optional, Set
from typing_extensions import Self

class PlaylistItem(BaseModel):
    """
    A *playlistItem* resource identifies another resource, such as a video, that is included in a playlist. In addition, the playlistItem resource contains details about the included resource that pertain specifically to how that resource is used in that playlist. YouTube uses playlists to identify special collections of videos for a channel, such as: - uploaded videos - favorite videos - positively rated (liked) videos - watch history - watch later To be more specific, these lists are associated with a channel, which is a collection of a person, group, or company's videos, playlists, and other YouTube information. You can retrieve the playlist IDs for each of these lists from the channel resource for a given channel. You can then use the playlistItems.list method to retrieve any of those lists. You can also add or remove items from those lists by calling the playlistItems.insert and playlistItems.delete methods. For example, if a user gives a positive rating to a video, you would insert that video into the liked videos playlist for that user's channel.
    """ # noqa: E501
    content_details: Optional[PlaylistItemContentDetails] = Field(default=None, alias="contentDetails")
    etag: Optional[StrictStr] = Field(default=None, description="Etag of this resource.")
    id: Optional[StrictStr] = Field(default=None, description="The ID that YouTube uses to uniquely identify the playlist item.")
    kind: Optional[StrictStr] = Field(default='youtube#playlistItem', description="Identifies what kind of resource this is. Value: the fixed string \"youtube#playlistItem\".")
    snippet: Optional[PlaylistItemSnippet] = None
    status: Optional[PlaylistItemStatus] = None
    __properties: ClassVar[List[str]] = ["contentDetails", "etag", "id", "kind", "snippet", "status"]

    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 PlaylistItem 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 content_details
        if self.content_details:
            _dict['contentDetails'] = self.content_details.to_dict()
        # override the default output from pydantic by calling `to_dict()` of snippet
        if self.snippet:
            _dict['snippet'] = self.snippet.to_dict()
        # override the default output from pydantic by calling `to_dict()` of status
        if self.status:
            _dict['status'] = self.status.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "contentDetails": PlaylistItemContentDetails.from_dict(obj["contentDetails"]) if obj.get("contentDetails") is not None else None,
            "etag": obj.get("etag"),
            "id": obj.get("id"),
            "kind": obj.get("kind") if obj.get("kind") is not None else 'youtube#playlistItem',
            "snippet": PlaylistItemSnippet.from_dict(obj["snippet"]) if obj.get("snippet") is not None else None,
            "status": PlaylistItemStatus.from_dict(obj["status"]) if obj.get("status") is not None else None
        })
        return _obj


