from __future__ import annotations from collections.abc import Mapping from typing import TYPE_CHECKING, Any, TypeVar, cast from attrs import define as _attrs_define from attrs import field as _attrs_field from typing_extensions import Self from ..models.match_multiround_modes import MatchMultiroundModes from ..models.match_status import MatchStatus from ..types import UNSET, Unset if TYPE_CHECKING: from ..models.match_players import MatchPlayers from ..models.match_round import MatchRound T = TypeVar("T", bound="Match") @_attrs_define class Match: """ Attributes: id (int | Unset): title (str | Unset): internal_id (str | Unset): status (MatchStatus | Unset): status_display (str | Unset): rounds_count (int | Unset): use_points (bool | Unset): points_are_positions (bool | Unset): multiround_modes (MatchMultiroundModes | Unset): multiround_modes_display (None | str | Unset): creation_date (str | Unset): Example: 2026-08-01 10:00:00+00:00. playing_date (str | Unset): done_date (str | Unset): current_round (int | Unset): players (MatchPlayers | Unset): map of AAndTHasUserOrTeam pk (string key) -> MatschHasPlayerOrTeam pk rounds (list[MatchRound] | Unset): """ id: int | Unset = UNSET title: str | Unset = UNSET internal_id: str | Unset = UNSET status: MatchStatus | Unset = UNSET status_display: str | Unset = UNSET rounds_count: int | Unset = UNSET use_points: bool | Unset = UNSET points_are_positions: bool | Unset = UNSET multiround_modes: MatchMultiroundModes | Unset = UNSET multiround_modes_display: None | str | Unset = UNSET creation_date: str | Unset = UNSET playing_date: str | Unset = UNSET done_date: str | Unset = UNSET current_round: int | Unset = UNSET players: MatchPlayers | Unset = UNSET rounds: list[MatchRound] | Unset = UNSET additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> dict[str, Any]: id = self.id title = self.title internal_id = self.internal_id status: str | Unset = UNSET if not isinstance(self.status, Unset): status = self.status.value status_display = self.status_display rounds_count = self.rounds_count use_points = self.use_points points_are_positions = self.points_are_positions multiround_modes: str | Unset = UNSET if not isinstance(self.multiround_modes, Unset): multiround_modes = self.multiround_modes.value multiround_modes_display: None | str | Unset if isinstance(self.multiround_modes_display, Unset): multiround_modes_display = UNSET else: multiround_modes_display = self.multiround_modes_display creation_date = self.creation_date playing_date = self.playing_date done_date = self.done_date current_round = self.current_round players: dict[str, Any] | Unset = UNSET if not isinstance(self.players, Unset): players = self.players.to_dict() rounds: list[dict[str, Any]] | Unset = UNSET if not isinstance(self.rounds, Unset): rounds = [] for rounds_item_data in self.rounds: rounds_item = rounds_item_data.to_dict() rounds.append(rounds_item) field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if id is not UNSET: field_dict["id"] = id if title is not UNSET: field_dict["title"] = title if internal_id is not UNSET: field_dict["internal_id"] = internal_id if status is not UNSET: field_dict["status"] = status if status_display is not UNSET: field_dict["status_display"] = status_display if rounds_count is not UNSET: field_dict["rounds_count"] = rounds_count if use_points is not UNSET: field_dict["use_points"] = use_points if points_are_positions is not UNSET: field_dict["points_are_positions"] = points_are_positions if multiround_modes is not UNSET: field_dict["multiround_modes"] = multiround_modes if multiround_modes_display is not UNSET: field_dict["multiround_modes_display"] = multiround_modes_display if creation_date is not UNSET: field_dict["creation_date"] = creation_date if playing_date is not UNSET: field_dict["playing_date"] = playing_date if done_date is not UNSET: field_dict["done_date"] = done_date if current_round is not UNSET: field_dict["current_round"] = current_round if players is not UNSET: field_dict["players"] = players if rounds is not UNSET: field_dict["rounds"] = rounds return field_dict @classmethod def from_dict(cls, src_dict: Mapping[str, Any]) -> Self: from ..models.match_players import MatchPlayers from ..models.match_round import MatchRound d = dict(src_dict) id = d.pop("id", UNSET) title = d.pop("title", UNSET) internal_id = d.pop("internal_id", UNSET) _status = d.pop("status", UNSET) status: MatchStatus | Unset if isinstance(_status, Unset): status = UNSET else: status = MatchStatus(_status) status_display = d.pop("status_display", UNSET) rounds_count = d.pop("rounds_count", UNSET) use_points = d.pop("use_points", UNSET) points_are_positions = d.pop("points_are_positions", UNSET) _multiround_modes = d.pop("multiround_modes", UNSET) multiround_modes: MatchMultiroundModes | Unset if isinstance(_multiround_modes, Unset): multiround_modes = UNSET else: multiround_modes = MatchMultiroundModes(_multiround_modes) def _parse_multiround_modes_display(data: object) -> None | str | Unset: if data is None: return data if isinstance(data, Unset): return data return cast(None | str | Unset, data) multiround_modes_display = _parse_multiround_modes_display( d.pop("multiround_modes_display", UNSET) ) creation_date = d.pop("creation_date", UNSET) playing_date = d.pop("playing_date", UNSET) done_date = d.pop("done_date", UNSET) current_round = d.pop("current_round", UNSET) _players = d.pop("players", UNSET) players: MatchPlayers | Unset if isinstance(_players, Unset): players = UNSET else: players = MatchPlayers.from_dict(_players) _rounds = d.pop("rounds", UNSET) rounds: list[MatchRound] | Unset = UNSET if _rounds is not UNSET: rounds = [] for rounds_item_data in _rounds: rounds_item = MatchRound.from_dict(rounds_item_data) rounds.append(rounds_item) match = cls( id=id, title=title, internal_id=internal_id, status=status, status_display=status_display, rounds_count=rounds_count, use_points=use_points, points_are_positions=points_are_positions, multiround_modes=multiround_modes, multiround_modes_display=multiround_modes_display, creation_date=creation_date, playing_date=playing_date, done_date=done_date, current_round=current_round, players=players, rounds=rounds, ) match.additional_properties = d return match @property def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: return self.additional_properties[key] def __setitem__(self, key: str, value: Any) -> None: self.additional_properties[key] = value def __delitem__(self, key: str) -> None: del self.additional_properties[key] def __contains__(self, key: str) -> bool: return key in self.additional_properties