# generated by scripts/generate_messages.py

from twnet_parser.pretty_print import PrettyPrint
from twnet_parser.packer import Unpacker
from twnet_parser.packer import SANITIZE_CC, pack_int, pack_str
from typing import Literal

class MsgInfo(PrettyPrint):
    def __init__(
            self,
            token: int = 0,
            version: str = 'default',
            name: str = 'default',
            hostname: str = 'default',
            map: str = 'default',
            game_type: str = 'default',
            flags: int = 0,
            skill_level: int = 0,
            num_players: int = 0,
            max_players: int = 0,
            num_clients: int = 0,
            max_clients: int = 0,
            clients: bytes = b''
    ) -> None:
        self.message_type: Literal['connless'] = 'connless'
        self.message_name: str = 'connless.info'
        self.message_id: list[int] = [255, 255, 255, 255, 105, 110, 102, 51]

        self.token: int = token
        self.version: str = version
        self.name: str = name
        self.hostname: str = hostname
        self.map: str = map
        self.game_type: str = game_type
        self.flags: int = flags
        self.skill_level: int = skill_level
        self.num_players: int = num_players
        self.max_players: int = max_players
        self.num_clients: int = num_clients
        self.max_clients: int = max_clients
        self.clients: bytes = clients

    def __iter__(self):
        yield 'message_type', self.message_type
        yield 'message_name', self.message_name
        yield 'message_id', self.message_id

        yield 'token', self.token
        yield 'version', self.version
        yield 'name', self.name
        yield 'hostname', self.hostname
        yield 'map', self.map
        yield 'game_type', self.game_type
        yield 'flags', self.flags
        yield 'skill_level', self.skill_level
        yield 'num_players', self.num_players
        yield 'max_players', self.max_players
        yield 'num_clients', self.num_clients
        yield 'max_clients', self.max_clients
        yield 'clients', self.clients

    # 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, data: bytes) -> bool:
        unpacker = Unpacker(data)
        self.token = unpacker.get_int()
        self.version = unpacker.get_str(SANITIZE_CC)
        self.name = unpacker.get_str(SANITIZE_CC)
        self.hostname = unpacker.get_str(SANITIZE_CC)
        self.map = unpacker.get_str(SANITIZE_CC)
        self.game_type = unpacker.get_str(SANITIZE_CC)
        self.flags = unpacker.get_int()
        self.skill_level = unpacker.get_int()
        self.num_players = unpacker.get_int()
        self.max_players = unpacker.get_int()
        self.num_clients = unpacker.get_int()
        self.max_clients = unpacker.get_int()
        self.clients = unpacker.get_raw()
        return True

    def pack(self) -> bytes:
        return pack_int(self.token) + \
            pack_str(self.version) + \
            pack_str(self.name) + \
            pack_str(self.hostname) + \
            pack_str(self.map) + \
            pack_str(self.game_type) + \
            pack_int(self.flags) + \
            pack_int(self.skill_level) + \
            pack_int(self.num_players) + \
            pack_int(self.max_players) + \
            pack_int(self.num_clients) + \
            pack_int(self.max_clients) + \
            self.clients