using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeLongTermKeyRequestEventInfo : PacketInfoBase
{
	public override string Name => "Le Long Term Key Request Event";

	public override string DisplayGroup => "LE Controller";

	public LeLongTermKeyRequestEventInfo(LeLongTermKeyRequestEvent packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeLongTermKeyRequestEvent leLongTermKeyRequestEvent = (LeLongTermKeyRequestEvent)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent Code", "Subevent code for LE Long Term Key Request event", 8, FormatValue(leLongTermKeyRequestEvent.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection Handle", "Connection_Handle to be used to identify a connection between two Bluetooth devices", 16, FormatValue(leLongTermKeyRequestEvent.UserFields.ConnectionHandle, 16), "", "", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Random Number", "64-bit random number", 64, FormatValue(leLongTermKeyRequestEvent.UserFields.RandomNumber, 64), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Encrypted Diversifier", "16-bit encrypted diversifier", 16, FormatValue(leLongTermKeyRequestEvent.UserFields.EncryptedDiversifier, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeLongTermKeyRequestEvent leLongTermKeyRequestEvent = (LeLongTermKeyRequestEvent)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leLongTermKeyRequestEvent.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leLongTermKeyRequestEvent.UserFields.RandomNumber = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			leLongTermKeyRequestEvent.UserFields.EncryptedDiversifier = Convert.ToUInt32(value, 16);
		}
	}
}
