using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class ConnectionRequestInfo : PacketInfoBase
{
	public override string Name => "Connection Request";

	public override string DisplayGroup => "Link Control";

	public ConnectionRequestInfo(ConnectionRequest packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ConnectionRequest connectionRequest = (ConnectionRequest)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("BD_ADDR", "", 48, FormatValue(connectionRequest.UserFields.BdAddr, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Class of Device", "", 24, FormatValue(connectionRequest.UserFields.ClassOfDevice, 24), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Link Type", ConnectionRequest.UserFieldsWrapper.LinkTypeInfo.LinkTypeToDescription(), 8, FormatValue(connectionRequest.UserFields.LinkType, 8), ConnectionRequest.UserFieldsWrapper.LinkTypeInfo.LinkTypeToString(ConnectionRequest.UserFieldsWrapper.LinkTypeInfo.ValueToLinkType(connectionRequest.UserFields.LinkType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ConnectionRequest connectionRequest = (ConnectionRequest)packet;
		int num = -1;
		if (index == ++num)
		{
			connectionRequest.UserFields.BdAddr = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			connectionRequest.UserFields.ClassOfDevice = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			connectionRequest.UserFields.LinkType = Convert.ToUInt32(value, 16);
		}
	}
}
