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

import twnet_parser.msg6
from twnet_parser.connless_message import ConnlessMessage

import twnet_parser.messages6.connless.request_list as \
       connless_request_list
import twnet_parser.messages6.connless.list as \
       connless_list
import twnet_parser.messages6.connless.request_count as \
       connless_request_count
import twnet_parser.messages6.connless.count as \
       connless_count
import twnet_parser.messages6.connless.request_info as \
       connless_request_info
import twnet_parser.messages6.connless.info as \
       connless_info
import twnet_parser.messages6.connless.heartbeat as \
       connless_heartbeat
import twnet_parser.messages6.connless.forward_check as \
       connless_forward_check
import twnet_parser.messages6.connless.forward_response as \
       connless_forward_response
import twnet_parser.messages6.connless.forward_ok as \
       connless_forward_ok
import twnet_parser.messages6.connless.forward_error as \
       connless_forward_error

def match_connless6(msg_id: bytes, data: bytes) -> ConnlessMessage:
    msg: Optional[ConnlessMessage] = None

    if msg_id == twnet_parser.msg6.CONNLESS_REQUEST_LIST:
        msg = connless_request_list.MsgRequestList()
    elif msg_id == twnet_parser.msg6.CONNLESS_LIST:
        msg = connless_list.MsgList()
    elif msg_id == twnet_parser.msg6.CONNLESS_REQUEST_COUNT:
        msg = connless_request_count.MsgRequestCount()
    elif msg_id == twnet_parser.msg6.CONNLESS_COUNT:
        msg = connless_count.MsgCount()
    elif msg_id == twnet_parser.msg6.CONNLESS_REQUEST_INFO:
        msg = connless_request_info.MsgRequestInfo()
    elif msg_id == twnet_parser.msg6.CONNLESS_INFO:
        msg = connless_info.MsgInfo()
    elif msg_id == twnet_parser.msg6.CONNLESS_HEARTBEAT:
        msg = connless_heartbeat.MsgHeartbeat()
    elif msg_id == twnet_parser.msg6.CONNLESS_FORWARD_CHECK:
        msg = connless_forward_check.MsgForwardCheck()
    elif msg_id == twnet_parser.msg6.CONNLESS_FORWARD_RESPONSE:
        msg = connless_forward_response.MsgForwardResponse()
    elif msg_id == twnet_parser.msg6.CONNLESS_FORWARD_OK:
        msg = connless_forward_ok.MsgForwardOk()
    elif msg_id == twnet_parser.msg6.CONNLESS_FORWARD_ERROR:
        msg = connless_forward_error.MsgForwardError()

    if msg is None:
        raise ValueError(
            f"Error: unknown connless message id={msg_id!r} data={data[0]}"
        )

    msg.unpack(data)
    return msg
