from typing import Optional

from src.ezgg_lan_manager.types.TournamentBase import TournamentError


class Game:
    def __init__(self, id_: tuple[int, int], match_id: int, game_number: int, winner_id: Optional[int], score: Optional[tuple[int, int]], game_done: bool) -> None:
        self._id = id_
        self._match_id = match_id
        self._game_number = game_number
        self._winner_id = winner_id
        self._score = score
        self._done = game_done

    @property
    def id(self) -> tuple[int, int]:
        return self._id

    @property
    def is_done(self) -> bool:
        return self._done

    @property
    def winner(self) -> Optional[int]:
        return self._winner_id

    @property
    def number(self) -> int:
        return self._game_number


    def finish(self, winner_id: int, score: tuple[int, int], force: bool = False) -> None:
        """ NEVER call this outside Match or a Testsuite """
        if self._done and not force:
            raise TournamentError("Game is already finished")

        self._winner_id = winner_id
        self._score = score
        self._done = True
