using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeAddDeviceToResolvingListInfo : PacketInfoBase
{
	public override string Name => "Le Add Device To Resolving List";

	public override string DisplayGroup => "LE Controller";

	public LeAddDeviceToResolvingListInfo(LeAddDeviceToResolvingList packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeAddDeviceToResolvingList leAddDeviceToResolvingList = (LeAddDeviceToResolvingList)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Peer_Identity_Address_Type", PeerIdentityAddressTypeInfo.PeerIdentityAddressTypeToDescription(), 8, FormatValue(leAddDeviceToResolvingList.UserFields.PeerIdentityAddressType, 8), PeerIdentityAddressTypeInfo.PeerIdentityAddressTypeToString(PeerIdentityAddressTypeInfo.ValueToPeerIdentityAddressType(leAddDeviceToResolvingList.UserFields.PeerIdentityAddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Peer_Identity_Address", "Public or Random (static) Identity address of the peer device", 48, FormatValue(leAddDeviceToResolvingList.UserFields.PeerIdentityAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Peer_IRK", "IRK of the peer device", leAddDeviceToResolvingList.UserFields.PeerIrkList.Count * 8, FormatValue(leAddDeviceToResolvingList.UserFields.PeerIrkList, leAddDeviceToResolvingList.UserFields.PeerIrkList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Local_IRK", "IRK of the local device", leAddDeviceToResolvingList.UserFields.LocalIrkList.Count * 8, FormatValue(leAddDeviceToResolvingList.UserFields.LocalIrkList, leAddDeviceToResolvingList.UserFields.LocalIrkList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeAddDeviceToResolvingList leAddDeviceToResolvingList = (LeAddDeviceToResolvingList)packet;
		int num = -1;
		if (index == ++num)
		{
			leAddDeviceToResolvingList.UserFields.PeerIdentityAddressType = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leAddDeviceToResolvingList.UserFields.PeerIdentityAddress = Convert.ToUInt64(value, 16);
			return;
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, leAddDeviceToResolvingList.UserFields.PeerIrkList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				leAddDeviceToResolvingList.UserFields.PeerIrkList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, leAddDeviceToResolvingList.UserFields.LocalIrkList.Count);
			int num3 = 0;
			while (value.Length > 0)
			{
				string value3 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				leAddDeviceToResolvingList.UserFields.LocalIrkList[num3] = Convert.ToUInt32(value3, 16);
				num3++;
			}
		}
	}
}
