# 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 datetime import date
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from dupr_backend.models.pair_integer_integer import PairIntegerInteger
from dupr_backend.models.team import Team
from typing import Optional, Set
from typing_extensions import Self

class MatchRequest(BaseModel):
    """
    MatchRequest
    """ # noqa: E501
    venue: Optional[StrictStr] = Field(default=None, description="Since 2022, we are only using location field based on autocomplete")
    location: Optional[StrictStr] = None
    tournament: Optional[StrictStr] = None
    league: Optional[StrictStr] = None
    event_date: date = Field(alias="eventDate")
    team1: Team
    team2: Team
    score_format_id: Optional[StrictInt] = Field(default=None, alias="scoreFormatId")
    format: StrictStr
    event: Optional[StrictStr] = None
    match_type: Optional[StrictStr] = Field(default=None, alias="matchType")
    club_id: Optional[StrictInt] = Field(default=None, alias="clubId")
    notify: StrictBool
    scores: List[PairIntegerInteger]
    __properties: ClassVar[List[str]] = ["venue", "location", "tournament", "league", "eventDate", "team1", "team2", "scoreFormatId", "format", "event", "matchType", "clubId", "notify", "scores"]

    @field_validator('format')
    def format_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['SINGLES', 'DOUBLES']):
            raise ValueError("must be one of enum values ('SINGLES', 'DOUBLES')")
        return value

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

        if value not in set(['SIDE_ONLY', 'RALLY']):
            raise ValueError("must be one of enum values ('SIDE_ONLY', 'RALLY')")
        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 MatchRequest 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 team1
        if self.team1:
            _dict['team1'] = self.team1.to_dict()
        # override the default output from pydantic by calling `to_dict()` of team2
        if self.team2:
            _dict['team2'] = self.team2.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in scores (list)
        _items = []
        if self.scores:
            for _item_scores in self.scores:
                if _item_scores:
                    _items.append(_item_scores.to_dict())
            _dict['scores'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "venue": obj.get("venue"),
            "location": obj.get("location"),
            "tournament": obj.get("tournament"),
            "league": obj.get("league"),
            "eventDate": obj.get("eventDate"),
            "team1": Team.from_dict(obj["team1"]) if obj.get("team1") is not None else None,
            "team2": Team.from_dict(obj["team2"]) if obj.get("team2") is not None else None,
            "scoreFormatId": obj.get("scoreFormatId"),
            "format": obj.get("format"),
            "event": obj.get("event"),
            "matchType": obj.get("matchType"),
            "clubId": obj.get("clubId"),
            "notify": obj.get("notify"),
            "scores": [PairIntegerInteger.from_dict(_item) for _item in obj["scores"]] if obj.get("scores") is not None else None
        })
        return _obj


