# 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 MsgRconAuthStatus(PrettyPrint):
    def __init__(
            self,
            chunk_header: Optional[ChunkHeader] = None,
            auth_level: int = 0,
            receive_commands: int = 0
    ) -> None:
        self.message_type: Literal['system', 'game'] = 'system'
        self.message_name: str = 'rcon_auth_status'
        self.system_message: bool = True
        self.message_id: int = 10
        if not chunk_header:
            chunk_header = ChunkHeader(version = '0.6')
        self.header: ChunkHeader = chunk_header

        self.auth_level: Optional[int] = auth_level
        self.receive_commands: Optional[int] = receive_commands

    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 'auth_level', self.auth_level
        yield 'receive_commands', self.receive_commands

    # 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.auth_level = unpacker.get_optional_int()
        self.receive_commands = unpacker.get_optional_int()
        return True

    def pack(self) -> bytes:
        return (pack_int(self.auth_level) if self.auth_level is not None else b'') + \
            (pack_int(self.receive_commands) if self.receive_commands is not None else b'')