# generated by scripts/generate_messages.py
from typing import Optional

import twnet_parser.msg6
from twnet_parser.net_message import NetMessage
from twnet_parser.ddnet_uuid import MsgDDNetUuid

import twnet_parser.messages6.system.info as \
       system6_info
import twnet_parser.messages6.system.map_change as \
       system6_map_change
import twnet_parser.messages6.system.map_data as \
       system6_map_data
import twnet_parser.messages6.system.con_ready as \
       system6_con_ready
import twnet_parser.messages6.system.snap as \
       system6_snap
import twnet_parser.messages6.system.snap_empty as \
       system6_snap_empty
import twnet_parser.messages6.system.snap_single as \
       system6_snap_single
import twnet_parser.messages6.system.input_timing as \
       system6_input_timing
import twnet_parser.messages6.system.rcon_auth_status as \
       system6_rcon_auth_status
import twnet_parser.messages6.system.rcon_line as \
       system6_rcon_line
import twnet_parser.messages6.system.ready as \
       system6_ready
import twnet_parser.messages6.system.enter_game as \
       system6_enter_game
import twnet_parser.messages6.system.input as \
       system6_input
import twnet_parser.messages6.system.rcon_cmd as \
       system6_rcon_cmd
import twnet_parser.messages6.system.rcon_auth as \
       system6_rcon_auth
import twnet_parser.messages6.system.request_map_data as \
       system6_request_map_data
import twnet_parser.messages6.system.ping as \
       system6_ping
import twnet_parser.messages6.system.ping_reply as \
       system6_ping_reply
import twnet_parser.messages6.system.rcon_cmd_add as \
       system6_rcon_cmd_add
import twnet_parser.messages6.system.rcon_cmd_remove as \
       system6_rcon_cmd_remove

def match_system6(msg_id: int, data: bytes) -> NetMessage:
    msg: Optional[NetMessage] = None

    if msg_id == twnet_parser.msg6.INFO:
        msg = system6_info.MsgInfo()
    elif msg_id == twnet_parser.msg6.MAP_CHANGE:
        msg = system6_map_change.MsgMapChange()
    elif msg_id == twnet_parser.msg6.MAP_DATA:
        msg = system6_map_data.MsgMapData()
    elif msg_id == twnet_parser.msg6.CON_READY:
        msg = system6_con_ready.MsgConReady()
    elif msg_id == twnet_parser.msg6.SNAP:
        msg = system6_snap.MsgSnap()
    elif msg_id == twnet_parser.msg6.SNAP_EMPTY:
        msg = system6_snap_empty.MsgSnapEmpty()
    elif msg_id == twnet_parser.msg6.SNAP_SINGLE:
        msg = system6_snap_single.MsgSnapSingle()
    elif msg_id == twnet_parser.msg6.INPUT_TIMING:
        msg = system6_input_timing.MsgInputTiming()
    elif msg_id == twnet_parser.msg6.RCON_AUTH_STATUS:
        msg = system6_rcon_auth_status.MsgRconAuthStatus()
    elif msg_id == twnet_parser.msg6.RCON_LINE:
        msg = system6_rcon_line.MsgRconLine()
    elif msg_id == twnet_parser.msg6.READY:
        msg = system6_ready.MsgReady()
    elif msg_id == twnet_parser.msg6.ENTER_GAME:
        msg = system6_enter_game.MsgEnterGame()
    elif msg_id == twnet_parser.msg6.INPUT:
        msg = system6_input.MsgInput()
    elif msg_id == twnet_parser.msg6.RCON_CMD:
        msg = system6_rcon_cmd.MsgRconCmd()
    elif msg_id == twnet_parser.msg6.RCON_AUTH:
        msg = system6_rcon_auth.MsgRconAuth()
    elif msg_id == twnet_parser.msg6.REQUEST_MAP_DATA:
        msg = system6_request_map_data.MsgRequestMapData()
    elif msg_id == twnet_parser.msg6.PING:
        msg = system6_ping.MsgPing()
    elif msg_id == twnet_parser.msg6.PING_REPLY:
        msg = system6_ping_reply.MsgPingReply()
    elif msg_id == twnet_parser.msg6.RCON_CMD_ADD:
        msg = system6_rcon_cmd_add.MsgRconCmdAdd()
    elif msg_id == twnet_parser.msg6.RCON_CMD_REMOVE:
        msg = system6_rcon_cmd_remove.MsgRconCmdRemove()

    # msg_id 0 is used by ddnet uuid messages
    # do not crash on those
    if msg is None:
        if msg_id != 0:
            raise ValueError(f"Error: unknown system message id={msg_id} data={data[0]}")
        msg = MsgDDNetUuid()

    msg.unpack(data)
    return msg
