# generated by scripts/generate_messages.py

from typing import Any, Dict

from twnet_parser.pretty_print import PrettyPrint
from twnet_parser.packer import Unpacker
from twnet_parser.packer import pack_int

class ObjDeGameInfo(PrettyPrint):
    def __init__(
            self,
            game_flags: int = 0,
            score_limit: int = 0,
            time_limit: int = 0,
            match_num: int = 0,
            match_current: int = 0
    ) -> None:
        self.item_name: str = 'item.de_game_info'
        self.type_id: int = 14
        self.id: int = 0
        self.size: int = 5

        self.game_flags: int = game_flags
        self.score_limit: int = score_limit
        self.time_limit: int = time_limit
        self.match_num: int = match_num
        self.match_current: int = match_current

    def __iter__(self):
        yield 'item_name', self.item_name
        yield 'type_id', self.type_id
        yield 'id', self.id
        yield 'size', self.size

        yield 'game_flags', self.game_flags
        yield 'score_limit', self.score_limit
        yield 'time_limit', self.time_limit
        yield 'match_num', self.match_num
        yield 'match_current', self.match_current

    def to_dict_payload_only(self) -> Dict[str, Any]:
        return {
            'game_flags': self.game_flags,
            'score_limit': self.score_limit,
            'time_limit': self.time_limit,
            'match_num': self.match_num,
            'match_current': self.match_current
        }

    # first byte of data
    # has to be the first byte of the message payload
    # NOT the chunk header and NOT the message id
    def unpack(self, unpacker: Unpacker) -> bool:
        self.game_flags = unpacker.get_int() # TODO: this is a flag
        self.score_limit = unpacker.get_int()
        self.time_limit = unpacker.get_int()
        self.match_num = unpacker.get_int()
        self.match_current = unpacker.get_int()
        return True

    def pack(self) -> bytes:
        return pack_int(self.game_flags) + \
            pack_int(self.score_limit) + \
            pack_int(self.time_limit) + \
            pack_int(self.match_num) + \
            pack_int(self.match_current)