using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class RemoteOobExtendedDataRequestReplyInfo : PacketInfoBase
{
	public override string Name => "Remote Oob Extended Data Request Reply";

	public override string DisplayGroup => "Link Control";

	public RemoteOobExtendedDataRequestReplyInfo(RemoteOobExtendedDataRequestReply packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RemoteOobExtendedDataRequestReply remoteOobExtendedDataRequestReply = (RemoteOobExtendedDataRequestReply)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("BD_ADDR", "BD_ADDR of remote device from which the C and R values were received.", 48, FormatValue(remoteOobExtendedDataRequestReply.UserFields.BdAddr, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("C_192", "Simple Pairing Hash C derived from the P-192 public key.", remoteOobExtendedDataRequestReply.UserFields.C192List.Count * 8, FormatValue(remoteOobExtendedDataRequestReply.UserFields.C192List, remoteOobExtendedDataRequestReply.UserFields.C192List.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("R_192", "Simple Pairing Randomizer associated with the P-192 public key.", remoteOobExtendedDataRequestReply.UserFields.R192List.Count * 8, FormatValue(remoteOobExtendedDataRequestReply.UserFields.R192List, remoteOobExtendedDataRequestReply.UserFields.R192List.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("C_256", "Simple Pairing Hash C derived from the P-256 public key.", remoteOobExtendedDataRequestReply.UserFields.C256List.Count * 8, FormatValue(remoteOobExtendedDataRequestReply.UserFields.C256List, remoteOobExtendedDataRequestReply.UserFields.C256List.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("R_256", "Simple Pairing Randomizer associated with the P-256 public key.", remoteOobExtendedDataRequestReply.UserFields.R256List.Count * 8, FormatValue(remoteOobExtendedDataRequestReply.UserFields.R256List, remoteOobExtendedDataRequestReply.UserFields.R256List.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		RemoteOobExtendedDataRequestReply remoteOobExtendedDataRequestReply = (RemoteOobExtendedDataRequestReply)packet;
		int num = -1;
		if (index == ++num)
		{
			remoteOobExtendedDataRequestReply.UserFields.BdAddr = Convert.ToUInt64(value, 16);
			return;
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, remoteOobExtendedDataRequestReply.UserFields.C192List.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				remoteOobExtendedDataRequestReply.UserFields.C192List[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, remoteOobExtendedDataRequestReply.UserFields.R192List.Count);
			int num3 = 0;
			while (value.Length > 0)
			{
				string value3 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				remoteOobExtendedDataRequestReply.UserFields.R192List[num3] = Convert.ToUInt32(value3, 16);
				num3++;
			}
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, remoteOobExtendedDataRequestReply.UserFields.C256List.Count);
			int num4 = 0;
			while (value.Length > 0)
			{
				string value4 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				remoteOobExtendedDataRequestReply.UserFields.C256List[num4] = Convert.ToUInt32(value4, 16);
				num4++;
			}
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, remoteOobExtendedDataRequestReply.UserFields.R256List.Count);
			int num5 = 0;
			while (value.Length > 0)
			{
				string value5 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				remoteOobExtendedDataRequestReply.UserFields.R256List[num5] = Convert.ToUInt32(value5, 16);
				num5++;
			}
		}
	}
}
