using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class RfGetListenModeRoutingNtfInfo : PacketInfoBase
{
	public override string Name => "Rf Get Listen Mode Routing Ntf";

	public override string DisplayGroup => "RF Management";

	public RfGetListenModeRoutingNtfInfo(RfGetListenModeRoutingNtf packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RfGetListenModeRoutingNtf rfGetListenModeRoutingNtf = (RfGetListenModeRoutingNtf)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("More", MoreFieldValuesInfo.MoreFieldValuesToDescription(), 8, FormatValue(rfGetListenModeRoutingNtf.UserFields.More, 8), MoreFieldValuesInfo.MoreFieldValuesToString(MoreFieldValuesInfo.ValueToMoreFieldValues(rfGetListenModeRoutingNtf.UserFields.More)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number of Routing Entries", "The number of Routing Entry fields to follow (n). If the Listen Mode Routing Table is empty, the value of this field is 0x00 and there are no Routing Entries following.", 8, FormatValue(rfGetListenModeRoutingNtf.UserFields.NumberOfRoutingEntries, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < rfGetListenModeRoutingNtf.UserFields.RoutingEntryList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Type[" + i + "]", TlvCodingForListenModeRoutingInfo.TlvCodingForListenModeRoutingToDescription(), 8, FormatValue(rfGetListenModeRoutingNtf.UserFields.RoutingEntryList[i].Type, 8), TlvCodingForListenModeRoutingInfo.TlvCodingForListenModeRoutingToString(TlvCodingForListenModeRoutingInfo.ValueToTlvCodingForListenModeRouting(rfGetListenModeRoutingNtf.UserFields.RoutingEntryList[i].Type)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Length[" + i + "]", "The length of Value (x).", 8, FormatValue(rfGetListenModeRoutingNtf.UserFields.RoutingEntryList[i].Length, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Value[" + i + "]", "Value of the Routing TLV.", rfGetListenModeRoutingNtf.UserFields.RoutingEntryList[i].ValueList.Count * 8, FormatValue(rfGetListenModeRoutingNtf.UserFields.RoutingEntryList[i].ValueList, rfGetListenModeRoutingNtf.UserFields.RoutingEntryList[i].ValueList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

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