# coding: utf-8

"""
    DUPR Backend APIs

    Internal RESTful APIs to access DUPR ratings, users and provide matches.

    The version of the OpenAPI document: v1.0.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 pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Union
from dupr_backend.models.activity_user import ActivityUser
from dupr_backend.models.match import Match
from dupr_backend.models.post_reaction_response import PostReactionResponse
from typing import Optional, Set
from typing_extensions import Self

class PostResponse(BaseModel):
    """
    PostResponse
    """ # noqa: E501
    id: StrictStr
    activity_id: StrictStr = Field(alias="activityId")
    actor: ActivityUser
    verb: StrictStr
    content: StrictStr
    reaction_counts: Dict[str, Union[StrictFloat, StrictInt]] = Field(alias="reactionCounts")
    own_reactions: Dict[str, List[PostReactionResponse]] = Field(alias="ownReactions")
    tags: List[ActivityUser]
    hashtags: List[StrictStr]
    images: List[StrictStr]
    matches: List[Match]
    location: Dict[str, Dict[str, Any]]
    created_at: StrictInt = Field(alias="createdAt")
    updated_at: StrictInt = Field(alias="updatedAt")
    __properties: ClassVar[List[str]] = ["id", "activityId", "actor", "verb", "content", "reactionCounts", "ownReactions", "tags", "hashtags", "images", "matches", "location", "createdAt", "updatedAt"]

    @field_validator('verb')
    def verb_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['POST', 'MATCH']):
            raise ValueError("must be one of enum values ('POST', 'MATCH')")
        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 PostResponse 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 actor
        if self.actor:
            _dict['actor'] = self.actor.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each value in own_reactions (dict of array)
        _field_dict_of_array = {}
        if self.own_reactions:
            for _key_own_reactions in self.own_reactions:
                if self.own_reactions[_key_own_reactions] is not None:
                    _field_dict_of_array[_key_own_reactions] = [
                        _item.to_dict() for _item in self.own_reactions[_key_own_reactions]
                    ]
            _dict['ownReactions'] = _field_dict_of_array
        # override the default output from pydantic by calling `to_dict()` of each item in tags (list)
        _items = []
        if self.tags:
            for _item_tags in self.tags:
                if _item_tags:
                    _items.append(_item_tags.to_dict())
            _dict['tags'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in matches (list)
        _items = []
        if self.matches:
            for _item_matches in self.matches:
                if _item_matches:
                    _items.append(_item_matches.to_dict())
            _dict['matches'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "activityId": obj.get("activityId"),
            "actor": ActivityUser.from_dict(obj["actor"]) if obj.get("actor") is not None else None,
            "verb": obj.get("verb"),
            "content": obj.get("content"),
            "reactionCounts": obj.get("reactionCounts"),
            "ownReactions": dict(
                (_k,
                        [PostReactionResponse.from_dict(_item) for _item in _v]
                        if _v is not None
                        else None
                )
                for _k, _v in obj.get("ownReactions", {}).items()
            ),
            "tags": [ActivityUser.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None,
            "hashtags": obj.get("hashtags"),
            "images": obj.get("images"),
            "matches": [Match.from_dict(_item) for _item in obj["matches"]] if obj.get("matches") is not None else None,
            "location": obj.get("location"),
            "createdAt": obj.get("createdAt"),
            "updatedAt": obj.get("updatedAt")
        })
        return _obj


