# generated by scripts/generate_messages.py

from twnet_parser.pretty_print import PrettyPrint
from twnet_parser.packer import Unpacker
from twnet_parser.chunk_header import ChunkHeader
from twnet_parser.packer import pack_int
from typing import Literal, Optional

class MsgSvServerSettings(PrettyPrint):
    def __init__(
            self,
            chunk_header: Optional[ChunkHeader] = None,
            kick_vote: bool = False,
            kick_min: int = 0,
            spec_vote: bool = False,
            team_lock: bool = False,
            team_balance: bool = False,
            player_slots: int = 0
    ) -> None:
        self.message_type: Literal['system', 'game'] = 'game'
        self.message_name: str = 'sv_server_settings'
        self.system_message: bool = False
        self.message_id: int = 17
        if not chunk_header:
            chunk_header = ChunkHeader(version = '0.7')
        self.header: ChunkHeader = chunk_header

        self.kick_vote: bool = kick_vote
        self.kick_min: int = kick_min
        self.spec_vote: bool = spec_vote
        self.team_lock: bool = team_lock
        self.team_balance: bool = team_balance
        self.player_slots: int = player_slots

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

        yield 'kick_vote', self.kick_vote
        yield 'kick_min', self.kick_min
        yield 'spec_vote', self.spec_vote
        yield 'team_lock', self.team_lock
        yield 'team_balance', self.team_balance
        yield 'player_slots', self.player_slots

    # 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.kick_vote = unpacker.get_int() == 1
        self.kick_min = unpacker.get_int()
        self.spec_vote = unpacker.get_int() == 1
        self.team_lock = unpacker.get_int() == 1
        self.team_balance = unpacker.get_int() == 1
        self.player_slots = unpacker.get_int()
        return True

    def pack(self) -> bytes:
        return pack_int(self.kick_vote) + \
            pack_int(self.kick_min) + \
            pack_int(self.spec_vote) + \
            pack_int(self.team_lock) + \
            pack_int(self.team_balance) + \
            pack_int(self.player_slots)