# coding: utf-8

"""
    Giphy API

    Giphy API

    The version of the OpenAPI document: 1.0
    Contact: support@giphy.com
    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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from tester_sdk.models.gif_images import GifImages
from tester_sdk.models.user import User
from typing import Optional, Set
from typing_extensions import Self

class Gif(BaseModel):
    """
    Gif
    """ # noqa: E501
    bitly_url: Optional[StrictStr] = Field(default=None, description="The unique bit.ly URL for this GIF")
    content_url: Optional[StrictStr] = Field(default=None, description="Currently unused")
    create_datetime: Optional[datetime] = Field(default=None, description="The date this GIF was added to the GIPHY database.")
    embded_url: Optional[StrictStr] = Field(default=None, description="A URL used for embedding this GIF")
    featured_tags: Optional[List[StrictStr]] = Field(default=None, description="An array of featured tags for this GIF (Note: Not available when using the Public Beta Key) ")
    id: Optional[StrictStr] = Field(default=None, description="This GIF's unique ID")
    images: Optional[GifImages] = None
    import_datetime: Optional[datetime] = Field(default=None, description="The creation or upload date from this GIF's source.")
    rating: Optional[StrictStr] = Field(default=None, description="The MPAA-style rating for this content. Examples include Y, G, PG, PG-13 and R")
    slug: Optional[StrictStr] = Field(default=None, description="The unique slug used in this GIF's URL")
    source: Optional[StrictStr] = Field(default=None, description="The page on which this GIF was found")
    source_post_url: Optional[StrictStr] = Field(default=None, description="The URL of the webpage on which this GIF was found.")
    source_tld: Optional[StrictStr] = Field(default=None, description="The top level domain of the source URL.")
    tags: Optional[List[StrictStr]] = Field(default=None, description="An array of tags for this GIF (Note: Not available when using the Public Beta Key) ")
    type: Optional[StrictStr] = Field(default='gif', description="Type of the gif. By default, this is almost always gif")
    update_datetime: Optional[datetime] = Field(default=None, description="The date on which this GIF was last updated.")
    url: Optional[StrictStr] = Field(default=None, description="The unique URL for this GIF")
    user: Optional[User] = None
    username: Optional[StrictStr] = Field(default=None, description="The username this GIF is attached to, if applicable")
    __properties: ClassVar[List[str]] = ["bitly_url", "content_url", "create_datetime", "embded_url", "featured_tags", "id", "images", "import_datetime", "rating", "slug", "source", "source_post_url", "source_tld", "tags", "type", "update_datetime", "url", "user", "username"]

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

        if value not in set(['gif']):
            raise ValueError("must be one of enum values ('gif')")
        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 Gif 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 images
        if self.images:
            _dict['images'] = self.images.to_dict()
        # override the default output from pydantic by calling `to_dict()` of user
        if self.user:
            _dict['user'] = self.user.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "bitly_url": obj.get("bitly_url"),
            "content_url": obj.get("content_url"),
            "create_datetime": obj.get("create_datetime"),
            "embded_url": obj.get("embded_url"),
            "featured_tags": obj.get("featured_tags"),
            "id": obj.get("id"),
            "images": GifImages.from_dict(obj["images"]) if obj.get("images") is not None else None,
            "import_datetime": obj.get("import_datetime"),
            "rating": obj.get("rating"),
            "slug": obj.get("slug"),
            "source": obj.get("source"),
            "source_post_url": obj.get("source_post_url"),
            "source_tld": obj.get("source_tld"),
            "tags": obj.get("tags"),
            "type": obj.get("type") if obj.get("type") is not None else 'gif',
            "update_datetime": obj.get("update_datetime"),
            "url": obj.get("url"),
            "user": User.from_dict(obj["user"]) if obj.get("user") is not None else None,
            "username": obj.get("username")
        })
        return _obj


