# 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 ObjGameDataFlag(PrettyPrint):
    def __init__(
            self,
            flag_carrier_red: int = 0,
            flag_carrier_blue: int = 0,
            flag_drop_tick_red: int = 0,
            flag_drop_tick_blue: int = 0
    ) -> None:
        self.item_name: str = 'item.game_data_flag'
        self.type_id: int = 8
        self.id: int = 0
        self.size: int = 4

        self.flag_carrier_red: int = flag_carrier_red
        self.flag_carrier_blue: int = flag_carrier_blue
        self.flag_drop_tick_red: int = flag_drop_tick_red
        self.flag_drop_tick_blue: int = flag_drop_tick_blue

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

        yield 'flag_carrier_red', self.flag_carrier_red
        yield 'flag_carrier_blue', self.flag_carrier_blue
        yield 'flag_drop_tick_red', self.flag_drop_tick_red
        yield 'flag_drop_tick_blue', self.flag_drop_tick_blue

    def to_dict_payload_only(self) -> Dict[str, Any]:
        return {
            'flag_carrier_red': self.flag_carrier_red,
            'flag_carrier_blue': self.flag_carrier_blue,
            'flag_drop_tick_red': self.flag_drop_tick_red,
            'flag_drop_tick_blue': self.flag_drop_tick_blue
        }

    # 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.flag_carrier_red = unpacker.get_int()
        self.flag_carrier_blue = unpacker.get_int()
        self.flag_drop_tick_red = unpacker.get_int()
        self.flag_drop_tick_blue = unpacker.get_int()
        return True

    def pack(self) -> bytes:
        return pack_int(self.flag_carrier_red) + \
            pack_int(self.flag_carrier_blue) + \
            pack_int(self.flag_drop_tick_red) + \
            pack_int(self.flag_drop_tick_blue)