using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

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

	public override string DisplayGroup => "LE Controller";

	public LeLongTermKeyRequestReplyInfo(LeLongTermKeyRequestReply packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeLongTermKeyRequestReply leLongTermKeyRequestReply = (LeLongTermKeyRequestReply)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection_Handle to be used to identify a connection. Range: 0x0000-0x0EFF. Reserved for future use (0x0F00 - 0x0FFF)", 16, FormatValue(leLongTermKeyRequestReply.UserFields.ConnectionHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Long_Term_Key", "128 bit long term key for the given connection", leLongTermKeyRequestReply.UserFields.LongTermKeyList.Count * 8, FormatValue(leLongTermKeyRequestReply.UserFields.LongTermKeyList, leLongTermKeyRequestReply.UserFields.LongTermKeyList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeLongTermKeyRequestReply leLongTermKeyRequestReply = (LeLongTermKeyRequestReply)packet;
		int num = -1;
		if (index == ++num)
		{
			leLongTermKeyRequestReply.UserFields.ConnectionHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, leLongTermKeyRequestReply.UserFields.LongTermKeyList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				leLongTermKeyRequestReply.UserFields.LongTermKeyList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
