using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class RfNfceeDiscoveryReqNtfInfo : PacketInfoBase
{
	public override string Name => "Rf Nfcee Discovery Req Ntf";

	public override string DisplayGroup => "RF Management";

	public RfNfceeDiscoveryReqNtfInfo(RfNfceeDiscoveryReqNtf packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RfNfceeDiscoveryReqNtf rfNfceeDiscoveryReqNtf = (RfNfceeDiscoveryReqNtf)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Number Of Information Entries", "The number of information entries to follow (n).", 8, FormatValue(rfNfceeDiscoveryReqNtf.UserFields.NumberOfInformationEntries, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Type[" + i + "]", RfNfceeDiscoveryReqNtf.InformationEntrySubField.TypeInfo.TypeToDescription(), 8, FormatValue(rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].Type, 8), RfNfceeDiscoveryReqNtf.InformationEntrySubField.TypeInfo.TypeToString(RfNfceeDiscoveryReqNtf.InformationEntrySubField.TypeInfo.ValueToType(rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].Type)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Length[" + i + "]", "The length of Value (x).", 8, FormatValue(rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].Length, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			if (rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].Length == 3)
			{
				fieldInfoList.Add(new PacketFieldInfo("Value[" + i + "]", "Value of the Information Entry.\r\n\r\n" + RfNfceeDiscoveryReqNtf.InformationEntrySubField.ValueInfo.ValueToDescription(), rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].ValueList.Count * 8, FormatValue(rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].ValueList, rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].ValueList.Count * 8, includeSpaces: false), RfNfceeDiscoveryReqNtf.InformationEntrySubField.ValueInfo.ValueToString(RfNfceeDiscoveryReqNtf.InformationEntrySubField.ValueInfo.ValueToValue(Conversions.UintListToUint(rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].ValueList))), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			}
			else
			{
				fieldInfoList.Add(new PacketFieldInfo("Value[" + i + "]", "Value of the Information Entry.", rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].ValueList.Count * 8, FormatValue(rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].ValueList, rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].ValueList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			}
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		RfNfceeDiscoveryReqNtf rfNfceeDiscoveryReqNtf = (RfNfceeDiscoveryReqNtf)packet;
		int num = -1;
		if (index == ++num)
		{
			rfNfceeDiscoveryReqNtf.UserFields.NumberOfInformationEntries = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList.Count; i++)
		{
			if (index == ++num)
			{
				rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].Type = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].Length = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				value = AddLeadingZerosAndCheckValueStringLength(value, rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].ValueList.Count);
				int num2 = 0;
				while (value.Length > 0)
				{
					string value2 = value.Substring(0, 2);
					value = value.Remove(0, 2);
					rfNfceeDiscoveryReqNtf.UserFields.InformationEntryList[i].ValueList[num2] = Convert.ToUInt32(value2, 16);
					num2++;
				}
			}
		}
	}
}
