# 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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from youtube_ti.models.comment_snippet_author_channel_id import CommentSnippetAuthorChannelId
from typing import Optional, Set
from typing_extensions import Self

class CommentSnippet(BaseModel):
    """
    Basic details about a comment, such as its author and text.
    """ # noqa: E501
    author_channel_id: Optional[CommentSnippetAuthorChannelId] = Field(default=None, alias="authorChannelId")
    author_channel_url: Optional[StrictStr] = Field(default=None, description="Link to the author's YouTube channel, if any.", alias="authorChannelUrl")
    author_display_name: Optional[StrictStr] = Field(default=None, description="The name of the user who posted the comment.", alias="authorDisplayName")
    author_profile_image_url: Optional[StrictStr] = Field(default=None, description="The URL for the avatar of the user who posted the comment.", alias="authorProfileImageUrl")
    can_rate: Optional[StrictBool] = Field(default=None, description="Whether the current viewer can rate this comment.", alias="canRate")
    channel_id: Optional[StrictStr] = Field(default=None, description="The id of the corresponding YouTube channel. In case of a channel comment this is the channel the comment refers to. In case of a video comment it's the video's channel.", alias="channelId")
    like_count: Optional[StrictInt] = Field(default=None, description="The total number of likes this comment has received.", alias="likeCount")
    moderation_status: Optional[StrictStr] = Field(default=None, description="The comment's moderation status. Will not be set if the comments were requested through the id filter.", alias="moderationStatus")
    parent_id: Optional[StrictStr] = Field(default=None, description="The unique id of the parent comment, only set for replies.", alias="parentId")
    published_at: Optional[datetime] = Field(default=None, description="The date and time when the comment was originally published.", alias="publishedAt")
    text_display: Optional[StrictStr] = Field(default=None, description="The comment's text. The format is either plain text or HTML dependent on what has been requested. Even the plain text representation may differ from the text originally posted in that it may replace video links with video titles etc.", alias="textDisplay")
    text_original: Optional[StrictStr] = Field(default=None, description="The comment's original raw text as initially posted or last updated. The original text will only be returned if it is accessible to the viewer, which is only guaranteed if the viewer is the comment's author.", alias="textOriginal")
    updated_at: Optional[datetime] = Field(default=None, description="The date and time when the comment was last updated.", alias="updatedAt")
    video_id: Optional[StrictStr] = Field(default=None, description="The ID of the video the comment refers to, if any.", alias="videoId")
    viewer_rating: Optional[StrictStr] = Field(default=None, description="The rating the viewer has given to this comment. For the time being this will never return RATE_TYPE_DISLIKE and instead return RATE_TYPE_NONE. This may change in the future.", alias="viewerRating")
    __properties: ClassVar[List[str]] = ["authorChannelId", "authorChannelUrl", "authorDisplayName", "authorProfileImageUrl", "canRate", "channelId", "likeCount", "moderationStatus", "parentId", "publishedAt", "textDisplay", "textOriginal", "updatedAt", "videoId", "viewerRating"]

    @field_validator('moderation_status')
    def moderation_status_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['published', 'heldForReview', 'likelySpam', 'rejected']):
            raise ValueError("must be one of enum values ('published', 'heldForReview', 'likelySpam', 'rejected')")
        return value

    @field_validator('viewer_rating')
    def viewer_rating_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['none', 'like', 'dislike']):
            raise ValueError("must be one of enum values ('none', 'like', 'dislike')")
        return value

    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 CommentSnippet 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 author_channel_id
        if self.author_channel_id:
            _dict['authorChannelId'] = self.author_channel_id.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "authorChannelId": CommentSnippetAuthorChannelId.from_dict(obj["authorChannelId"]) if obj.get("authorChannelId") is not None else None,
            "authorChannelUrl": obj.get("authorChannelUrl"),
            "authorDisplayName": obj.get("authorDisplayName"),
            "authorProfileImageUrl": obj.get("authorProfileImageUrl"),
            "canRate": obj.get("canRate"),
            "channelId": obj.get("channelId"),
            "likeCount": obj.get("likeCount"),
            "moderationStatus": obj.get("moderationStatus"),
            "parentId": obj.get("parentId"),
            "publishedAt": obj.get("publishedAt"),
            "textDisplay": obj.get("textDisplay"),
            "textOriginal": obj.get("textOriginal"),
            "updatedAt": obj.get("updatedAt"),
            "videoId": obj.get("videoId"),
            "viewerRating": obj.get("viewerRating")
        })
        return _obj


