using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeRpaOffloadAddIrkToListInfo : PacketInfoBase
{
	public override string Name => "Le Rpa Offload Add Irk To List";

	public override string DisplayGroup => "Vendor Specific";

	public LeRpaOffloadAddIrkToListInfo(LeRpaOffloadAddIrkToList packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeRpaOffloadAddIrkToList leRpaOffloadAddIrkToList = (LeRpaOffloadAddIrkToList)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("RPA_offload_opcode", "Add IRK to the list", 8, FormatValue(leRpaOffloadAddIrkToList.UserFields.RpaOffloadOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LE_IRK", "LE IRK (1st byte LSB)", leRpaOffloadAddIrkToList.UserFields.LeIrkList.Count * 8, FormatValue(leRpaOffloadAddIrkToList.UserFields.LeIrkList, leRpaOffloadAddIrkToList.UserFields.LeIrkList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Address_Type", DeviceAddressTypeInfo.DeviceAddressTypeToDescription(), 8, FormatValue(leRpaOffloadAddIrkToList.UserFields.AddressType, 8), DeviceAddressTypeInfo.DeviceAddressTypeToString(DeviceAddressTypeInfo.ValueToDeviceAddressType(leRpaOffloadAddIrkToList.UserFields.AddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LE_Device_Address", "Public or Random address associated to IRK (1st byte LSB)", 48, FormatValue(leRpaOffloadAddIrkToList.UserFields.LeDeviceAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeRpaOffloadAddIrkToList leRpaOffloadAddIrkToList = (LeRpaOffloadAddIrkToList)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field RpaOffloadOpcode");
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, leRpaOffloadAddIrkToList.UserFields.LeIrkList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				leRpaOffloadAddIrkToList.UserFields.LeIrkList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			leRpaOffloadAddIrkToList.UserFields.AddressType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leRpaOffloadAddIrkToList.UserFields.LeDeviceAddress = Convert.ToUInt64(value, 16);
		}
	}
}
