using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class NfceeDiscoverNtfInfo : PacketInfoBase
{
	public override string Name => "Nfcee Discover Ntf";

	public override string DisplayGroup => "NFCEE Management";

	public NfceeDiscoverNtfInfo(NfceeDiscoverNtf packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		NfceeDiscoverNtf nfceeDiscoverNtf = (NfceeDiscoverNtf)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("NFCEE ID", NfceeIdsInfo.NfceeIdsToDescription(), 8, FormatValue(nfceeDiscoverNtf.UserFields.NfceeId, 8), NfceeIdsInfo.NfceeIdsToString(NfceeIdsInfo.ValueToNfceeIds(nfceeDiscoverNtf.UserFields.NfceeId)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("NFCEE Status", NfceeDiscoverNtf.UserFieldsWrapper.NfceeStatusInfo.NfceeStatusToDescription(), 8, FormatValue(nfceeDiscoverNtf.UserFields.NfceeStatus, 8), NfceeDiscoverNtf.UserFieldsWrapper.NfceeStatusInfo.NfceeStatusToString(NfceeDiscoverNtf.UserFieldsWrapper.NfceeStatusInfo.ValueToNfceeStatus(nfceeDiscoverNtf.UserFields.NfceeStatus)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number of Protocol Information Entries", "The number of Supported NFCEE Protocol fields to follow (n).", 8, FormatValue(nfceeDiscoverNtf.UserFields.NumberOfProtocolInformationEntries, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < nfceeDiscoverNtf.UserFields.SupportedNfceeProtocolsList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Supported NFCEE Protocols[" + i + "]", NfceeProtocolsAndInterfacesInfo.NfceeProtocolsAndInterfacesToDescription(), 8, FormatValue(nfceeDiscoverNtf.UserFields.SupportedNfceeProtocolsList[i], 8), NfceeProtocolsAndInterfacesInfo.NfceeProtocolsAndInterfacesToString(NfceeProtocolsAndInterfacesInfo.ValueToNfceeProtocolsAndInterfaces(nfceeDiscoverNtf.UserFields.SupportedNfceeProtocolsList[i])), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
		fieldInfoList.Add(new PacketFieldInfo("Number of NFCEE Information TLVs", "Number of NFCEE Information TLV fields to follow (m).", 8, FormatValue(nfceeDiscoverNtf.UserFields.NumberOfNfceeInformationTlvs, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int j = 0; j < nfceeDiscoverNtf.UserFields.NfceeInformationTlvList.Count; j++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Type[" + j + "]", NfceeDiscoverNtf.NfceeInformationTlvSubField.TypeInfo.TypeToDescription(), 8, FormatValue(nfceeDiscoverNtf.UserFields.NfceeInformationTlvList[j].Type, 8), NfceeDiscoverNtf.NfceeInformationTlvSubField.TypeInfo.TypeToString(NfceeDiscoverNtf.NfceeInformationTlvSubField.TypeInfo.ValueToType(nfceeDiscoverNtf.UserFields.NfceeInformationTlvList[j].Type)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Length[" + j + "]", "The length of Value (x).", 8, FormatValue(nfceeDiscoverNtf.UserFields.NfceeInformationTlvList[j].Length, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Value[" + j + "]", "The Value of the NFCEE Information TLV.", nfceeDiscoverNtf.UserFields.NfceeInformationTlvList[j].ValueList.Count * 8, FormatValue(nfceeDiscoverNtf.UserFields.NfceeInformationTlvList[j].ValueList, nfceeDiscoverNtf.UserFields.NfceeInformationTlvList[j].ValueList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		NfceeDiscoverNtf nfceeDiscoverNtf = (NfceeDiscoverNtf)packet;
		int num = -1;
		if (index == ++num)
		{
			nfceeDiscoverNtf.UserFields.NfceeId = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			nfceeDiscoverNtf.UserFields.NfceeStatus = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			nfceeDiscoverNtf.UserFields.NumberOfProtocolInformationEntries = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < nfceeDiscoverNtf.UserFields.SupportedNfceeProtocolsList.Count; i++)
		{
			if (index == ++num)
			{
				nfceeDiscoverNtf.UserFields.SupportedNfceeProtocolsList[i] = Convert.ToUInt32(value, 16);
				return;
			}
		}
		if (index == ++num)
		{
			nfceeDiscoverNtf.UserFields.NumberOfNfceeInformationTlvs = Convert.ToUInt32(value, 16);
			return;
		}
		for (int j = 0; j < nfceeDiscoverNtf.UserFields.NfceeInformationTlvList.Count; j++)
		{
			if (index == ++num)
			{
				nfceeDiscoverNtf.UserFields.NfceeInformationTlvList[j].Type = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				nfceeDiscoverNtf.UserFields.NfceeInformationTlvList[j].Length = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				value = AddLeadingZerosAndCheckValueStringLength(value, nfceeDiscoverNtf.UserFields.NfceeInformationTlvList[j].ValueList.Count);
				int num2 = 0;
				while (value.Length > 0)
				{
					string value2 = value.Substring(0, 2);
					value = value.Remove(0, 2);
					nfceeDiscoverNtf.UserFields.NfceeInformationTlvList[j].ValueList[num2] = Convert.ToUInt32(value2, 16);
					num2++;
				}
			}
		}
	}
}
