# 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.score_format_response import ScoreFormatResponse
from dupr_backend.models.team_response import TeamResponse
from typing import Optional, Set
from typing_extensions import Self

class LeagueMatchResponse(BaseModel):
    """
    LeagueMatchResponse
    """ # noqa: E501
    league_match_id: StrictInt = Field(alias="leagueMatchId")
    match_id: Optional[StrictInt] = Field(default=None, alias="matchId")
    registration_id: StrictInt = Field(alias="registrationId")
    league_id: StrictInt = Field(alias="leagueId")
    bracket_id: StrictInt = Field(alias="bracketId")
    user_id: Optional[StrictInt] = Field(default=None, alias="userId")
    league_name: StrictStr = Field(alias="leagueName")
    bracket_name: StrictStr = Field(alias="bracketName")
    event_format: StrictStr = Field(alias="eventFormat")
    score_format: ScoreFormatResponse = Field(alias="scoreFormat")
    match_date: date = Field(alias="matchDate")
    confirmed: StrictBool
    teams: List[TeamResponse]
    status: Optional[StrictStr] = None
    match_score_added: StrictBool = Field(alias="matchScoreAdded")
    league_match_status: Optional[StrictStr] = Field(default=None, alias="leagueMatchStatus")
    round: Optional[StrictInt] = None
    start_date: StrictStr = Field(alias="startDate")
    end_date: StrictStr = Field(alias="endDate")
    venue: StrictStr
    location: StrictStr
    is_forfeited: StrictBool = Field(alias="isForfeited")
    tag: Optional[StrictStr] = None
    in_queue: StrictBool = Field(alias="inQueue")
    no_of_games: StrictInt = Field(alias="noOfGames")
    tbd_1: StrictInt
    tbd_2: StrictInt
    match_slot: StrictInt = Field(alias="matchSlot")
    is_bye_match: StrictBool = Field(alias="isByeMatch")
    is_team_1_tbd: Optional[StrictBool] = None
    is_team_2_tbd: Optional[StrictBool] = None
    display_identity: StrictStr = Field(alias="displayIdentity")
    is_next_round_confirmed: StrictBool = Field(alias="isNextRoundConfirmed")
    impacted_draw: StrictBool = Field(alias="impactedDraw")
    forfeited: Optional[StrictBool] = None
    bye_match: Optional[StrictBool] = Field(default=None, alias="byeMatch")
    next_round_confirmed: Optional[StrictBool] = Field(default=None, alias="nextRoundConfirmed")
    __properties: ClassVar[List[str]] = ["leagueMatchId", "matchId", "registrationId", "leagueId", "bracketId", "userId", "leagueName", "bracketName", "eventFormat", "scoreFormat", "matchDate", "confirmed", "teams", "status", "matchScoreAdded", "leagueMatchStatus", "round", "startDate", "endDate", "venue", "location", "isForfeited", "tag", "inQueue", "noOfGames", "tbd_1", "tbd_2", "matchSlot", "isByeMatch", "is_team_1_tbd", "is_team_2_tbd", "displayIdentity", "isNextRoundConfirmed", "impactedDraw", "forfeited", "byeMatch", "nextRoundConfirmed"]

    @field_validator('event_format')
    def event_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('status')
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['ACTIVE', 'INACTIVE', 'UPCOMING', 'IN_PROGRESS', 'COMPLETE', 'CANCELLED', 'NOT_CONFIRMED', 'INVITED', 'CONFIRMED', 'MATCH_BYE', 'PENDING', 'FORFEITED', 'DELETED', 'ONGOING', 'SUSPENDED_TOS_13']):
            raise ValueError("must be one of enum values ('ACTIVE', 'INACTIVE', 'UPCOMING', 'IN_PROGRESS', 'COMPLETE', 'CANCELLED', 'NOT_CONFIRMED', 'INVITED', 'CONFIRMED', 'MATCH_BYE', 'PENDING', 'FORFEITED', 'DELETED', 'ONGOING', 'SUSPENDED_TOS_13')")
        return value

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

        if value not in set(['ACTIVE', 'INACTIVE', 'UPCOMING', 'IN_PROGRESS', 'COMPLETE', 'CANCELLED', 'NOT_CONFIRMED', 'INVITED', 'CONFIRMED', 'MATCH_BYE', 'PENDING', 'FORFEITED', 'DELETED', 'ONGOING', 'SUSPENDED_TOS_13']):
            raise ValueError("must be one of enum values ('ACTIVE', 'INACTIVE', 'UPCOMING', 'IN_PROGRESS', 'COMPLETE', 'CANCELLED', 'NOT_CONFIRMED', 'INVITED', 'CONFIRMED', 'MATCH_BYE', 'PENDING', 'FORFEITED', 'DELETED', 'ONGOING', 'SUSPENDED_TOS_13')")
        return value

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

        if value not in set(['EAST', 'WEST', 'NORTH', 'SOUTH', 'NORTH_EAST', 'SOUTH_WEST', 'NORTH_WEST', 'SOUTH_EAST']):
            raise ValueError("must be one of enum values ('EAST', 'WEST', 'NORTH', 'SOUTH', 'NORTH_EAST', 'SOUTH_WEST', 'NORTH_WEST', 'SOUTH_EAST')")
        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 LeagueMatchResponse 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 score_format
        if self.score_format:
            _dict['scoreFormat'] = self.score_format.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in teams (list)
        _items = []
        if self.teams:
            for _item_teams in self.teams:
                if _item_teams:
                    _items.append(_item_teams.to_dict())
            _dict['teams'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "leagueMatchId": obj.get("leagueMatchId"),
            "matchId": obj.get("matchId"),
            "registrationId": obj.get("registrationId"),
            "leagueId": obj.get("leagueId"),
            "bracketId": obj.get("bracketId"),
            "userId": obj.get("userId"),
            "leagueName": obj.get("leagueName"),
            "bracketName": obj.get("bracketName"),
            "eventFormat": obj.get("eventFormat"),
            "scoreFormat": ScoreFormatResponse.from_dict(obj["scoreFormat"]) if obj.get("scoreFormat") is not None else None,
            "matchDate": obj.get("matchDate"),
            "confirmed": obj.get("confirmed"),
            "teams": [TeamResponse.from_dict(_item) for _item in obj["teams"]] if obj.get("teams") is not None else None,
            "status": obj.get("status"),
            "matchScoreAdded": obj.get("matchScoreAdded"),
            "leagueMatchStatus": obj.get("leagueMatchStatus"),
            "round": obj.get("round"),
            "startDate": obj.get("startDate"),
            "endDate": obj.get("endDate"),
            "venue": obj.get("venue"),
            "location": obj.get("location"),
            "isForfeited": obj.get("isForfeited"),
            "tag": obj.get("tag"),
            "inQueue": obj.get("inQueue"),
            "noOfGames": obj.get("noOfGames"),
            "tbd_1": obj.get("tbd_1"),
            "tbd_2": obj.get("tbd_2"),
            "matchSlot": obj.get("matchSlot"),
            "isByeMatch": obj.get("isByeMatch"),
            "is_team_1_tbd": obj.get("is_team_1_tbd"),
            "is_team_2_tbd": obj.get("is_team_2_tbd"),
            "displayIdentity": obj.get("displayIdentity"),
            "isNextRoundConfirmed": obj.get("isNextRoundConfirmed"),
            "impactedDraw": obj.get("impactedDraw"),
            "forfeited": obj.get("forfeited"),
            "byeMatch": obj.get("byeMatch"),
            "nextRoundConfirmed": obj.get("nextRoundConfirmed")
        })
        return _obj


