# 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 ObjGameInfo(PrettyPrint):
    def __init__(
            self,
            game_flags: int = 0,
            game_state_flags: int = 0,
            round_start_tick: int = 0,
            warmup_timer: int = 0,
            score_limit: int = 0,
            time_limit: int = 0,
            round_num: int = 0,
            round_current: int = 0
    ) -> None:
        self.item_name: str = 'obj.game_info'
        self.type_id: int = 6
        self.id: int = 0
        self.size: int = 8

        self.game_flags: int = game_flags
        self.game_state_flags: int = game_state_flags
        self.round_start_tick: int = round_start_tick
        self.warmup_timer: int = warmup_timer
        self.score_limit: int = score_limit
        self.time_limit: int = time_limit
        self.round_num: int = round_num
        self.round_current: int = round_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 'game_state_flags', self.game_state_flags
        yield 'round_start_tick', self.round_start_tick
        yield 'warmup_timer', self.warmup_timer
        yield 'score_limit', self.score_limit
        yield 'time_limit', self.time_limit
        yield 'round_num', self.round_num
        yield 'round_current', self.round_current

    def to_dict_payload_only(self) -> Dict[str, Any]:
        return {
            'game_flags': self.game_flags,
            'game_state_flags': self.game_state_flags,
            'round_start_tick': self.round_start_tick,
            'warmup_timer': self.warmup_timer,
            'score_limit': self.score_limit,
            'time_limit': self.time_limit,
            'round_num': self.round_num,
            'round_current': self.round_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()
        self.game_state_flags = unpacker.get_int()
        self.round_start_tick = unpacker.get_int()
        self.warmup_timer = unpacker.get_int()
        self.score_limit = unpacker.get_int()
        self.time_limit = unpacker.get_int()
        self.round_num = unpacker.get_int()
        self.round_current = unpacker.get_int()
        return True

    def pack(self) -> bytes:
        return pack_int(self.game_flags) + \
            pack_int(self.game_state_flags) + \
            pack_int(self.round_start_tick) + \
            pack_int(self.warmup_timer) + \
            pack_int(self.score_limit) + \
            pack_int(self.time_limit) + \
            pack_int(self.round_num) + \
            pack_int(self.round_current)