# 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
import twnet_parser.enum6 as enum6

class ObjPlayerInfo(PrettyPrint):
    def __init__(
            self,
            local: int = 0,
            client_id: int = 0,
            team: int = enum6.Team.SPECTATORS.value,
            score: int = 0,
            latency: int = 0
    ) -> None:
        self.item_name: str = 'item.player_info'
        self.type_id: int = 10
        self.id: int = 0
        self.size: int = 5

        self.local: int = local
        self.client_id: int = client_id
        self.team: int = team
        self.score: int = score
        self.latency: int = latency

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

        yield 'local', self.local
        yield 'client_id', self.client_id
        yield 'team', self.team
        yield 'score', self.score
        yield 'latency', self.latency

    def to_dict_payload_only(self) -> Dict[str, Any]:
        return {
            'local': self.local,
            'client_id': self.client_id,
            'team': self.team,
            'score': self.score,
            'latency': self.latency
        }

    # 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.local = unpacker.get_int()
        self.client_id = unpacker.get_int()
        self.team = unpacker.get_int() # enum TEAM
        self.score = unpacker.get_int()
        self.latency = unpacker.get_int()
        return True

    def pack(self) -> bytes:
        return pack_int(self.local) + \
            pack_int(self.client_id) + \
            pack_int(self.team) + \
            pack_int(self.score) + \
            pack_int(self.latency)