# 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
from typing import Annotated
import twnet_parser.enum7 as enum7

class ObjDeClientInfo(PrettyPrint):
    def __init__(
            self,
            local: bool = False,
            team: int = enum7.Team.SPECTATORS.value,
            name: Annotated[list[int], 4] = \
                [0, 0, 0, 0],
            clan: Annotated[list[int], 3] = \
                [0, 0, 0],
            country: int = 0,
            skin_part_names: Annotated[list[list[int]], (6,6)] = \
                [[0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0],
                 [0, 0, 0, 0, 0, 0]],
            use_custom_colors: Annotated[list[bool], 6] = \
                [False, False, False, False, False, False],
            skin_part_colors: Annotated[list[int], 6] = \
                [0, 0, 0, 0, 0, 0]
    ) -> None:
        self.item_name: str = 'item.de_client_info'
        self.type_id: int = 13
        self.id: int = 0
        self.size: int = 8

        self.local: bool = local
        self.team: int = team
        self.name = name
        self.clan = clan
        self.country: int = country
        self.skin_part_names = skin_part_names
        self.use_custom_colors = use_custom_colors
        self.skin_part_colors = skin_part_colors

    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 'team', self.team
        yield 'name', self.name
        yield 'clan', self.clan
        yield 'country', self.country
        yield 'skin_part_names', self.skin_part_names
        yield 'use_custom_colors', self.use_custom_colors
        yield 'skin_part_colors', self.skin_part_colors

    def to_dict_payload_only(self) -> Dict[str, Any]:
        return {
            'local': self.local,
            'team': self.team,
            'name': self.name,
            'clan': self.clan,
            'country': self.country,
            'skin_part_names': self.skin_part_names,
            'use_custom_colors': self.use_custom_colors,
            'skin_part_colors': self.skin_part_colors
        }

    # 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() == 1
        self.team = unpacker.get_int() # enum TEAM
        for i in range(0, 4):
            self.name[i] = unpacker.get_int()
        for i in range(0, 3):
            self.clan[i] = unpacker.get_int()
        self.country = unpacker.get_int()
        for i in range(0, 6):
            sub: list[int] = []
            for k in range(0, 6):
                sub[k] = unpacker.get_int()
            self.skin_part_names[i] = sub
        for i in range(0, 6):
            self.use_custom_colors[i] = unpacker.get_int() == 1
        for i in range(0, 6):
            self.skin_part_colors[i] = unpacker.get_int()
        return True

    def pack(self) -> bytes:
        return pack_int(self.local) + \
            pack_int(self.team) + \
            b''.join([pack_int(x) for x in self.name]) + \
            b''.join([pack_int(x) for x in self.clan]) + \
            pack_int(self.country) + \
            b''.join([b''.join([pack_int(x) for x in sub]) for sub in self.skin_part_names]) + \
            b''.join([pack_int(x) for x in self.use_custom_colors]) + \
            b''.join([pack_int(x) for x in self.skin_part_colors])