# coding: utf-8

"""
    api

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

    The version of the OpenAPI document: 0.1.1
    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, StrictFloat, StrictInt
from typing import Any, ClassVar, Dict, List, Optional, Union
from shroudstone.stormgateworld.models.match_participant_player_leaderboard_entry_response import MatchParticipantPlayerLeaderboardEntryResponse
from shroudstone.stormgateworld.models.match_participant_player_response import MatchParticipantPlayerResponse
from shroudstone.stormgateworld.models.match_result import MatchResult
from shroudstone.stormgateworld.models.race import Race
from typing import Optional, Set
from typing_extensions import Self

class MatchParticipantResponse(BaseModel):
    """
    MatchParticipantResponse
    """ # noqa: E501
    player: Optional[MatchParticipantPlayerResponse] = None
    player_leaderboard_entry: Optional[MatchParticipantPlayerLeaderboardEntryResponse] = None
    race: Race
    team: StrictInt
    party: StrictInt
    mmr: Union[StrictFloat, StrictInt]
    mmr_updated: Optional[Union[StrictFloat, StrictInt]] = None
    mmr_diff: Optional[Union[StrictFloat, StrictInt]] = None
    result: Optional[MatchResult] = None
    ping: Optional[StrictInt] = None
    scores: Optional[Any] = None
    __properties: ClassVar[List[str]] = ["player", "player_leaderboard_entry", "race", "team", "party", "mmr", "mmr_updated", "mmr_diff", "result", "ping", "scores"]

    model_config = {
        "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 MatchParticipantResponse 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 player
        if self.player:
            _dict['player'] = self.player.to_dict()
        # override the default output from pydantic by calling `to_dict()` of player_leaderboard_entry
        if self.player_leaderboard_entry:
            _dict['player_leaderboard_entry'] = self.player_leaderboard_entry.to_dict()
        # set to None if player (nullable) is None
        # and model_fields_set contains the field
        if self.player is None and "player" in self.model_fields_set:
            _dict['player'] = None

        # set to None if player_leaderboard_entry (nullable) is None
        # and model_fields_set contains the field
        if self.player_leaderboard_entry is None and "player_leaderboard_entry" in self.model_fields_set:
            _dict['player_leaderboard_entry'] = None

        # set to None if mmr_updated (nullable) is None
        # and model_fields_set contains the field
        if self.mmr_updated is None and "mmr_updated" in self.model_fields_set:
            _dict['mmr_updated'] = None

        # set to None if mmr_diff (nullable) is None
        # and model_fields_set contains the field
        if self.mmr_diff is None and "mmr_diff" in self.model_fields_set:
            _dict['mmr_diff'] = None

        # set to None if result (nullable) is None
        # and model_fields_set contains the field
        if self.result is None and "result" in self.model_fields_set:
            _dict['result'] = None

        # set to None if ping (nullable) is None
        # and model_fields_set contains the field
        if self.ping is None and "ping" in self.model_fields_set:
            _dict['ping'] = None

        # set to None if scores (nullable) is None
        # and model_fields_set contains the field
        if self.scores is None and "scores" in self.model_fields_set:
            _dict['scores'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "player": MatchParticipantPlayerResponse.from_dict(obj["player"]) if obj.get("player") is not None else None,
            "player_leaderboard_entry": MatchParticipantPlayerLeaderboardEntryResponse.from_dict(obj["player_leaderboard_entry"]) if obj.get("player_leaderboard_entry") is not None else None,
            "race": obj.get("race"),
            "team": obj.get("team"),
            "party": obj.get("party"),
            "mmr": obj.get("mmr"),
            "mmr_updated": obj.get("mmr_updated"),
            "mmr_diff": obj.get("mmr_diff"),
            "result": obj.get("result"),
            "ping": obj.get("ping"),
            "scores": obj.get("scores")
        })
        return _obj


