using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class RfSetListenModeRoutingCmdInfo : PacketInfoBase
{
	public override string Name => "Rf Set Listen Mode Routing Cmd";

	public override string DisplayGroup => "RF Management";

	public RfSetListenModeRoutingCmdInfo(RfSetListenModeRoutingCmd packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RfSetListenModeRoutingCmd rfSetListenModeRoutingCmd = (RfSetListenModeRoutingCmd)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("More", MoreFieldValuesInfo.MoreFieldValuesToDescription(), 8, FormatValue(rfSetListenModeRoutingCmd.UserFields.More, 8), MoreFieldValuesInfo.MoreFieldValuesToString(MoreFieldValuesInfo.ValueToMoreFieldValues(rfSetListenModeRoutingCmd.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). This Control Message SHALL be at least one Routing Entry.", 8, FormatValue(rfSetListenModeRoutingCmd.UserFields.NumberOfRoutingEntries, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < rfSetListenModeRoutingCmd.UserFields.RoutingEntryList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Type[" + i + "]", TlvCodingForListenModeRoutingInfo.TlvCodingForListenModeRoutingToDescription(), 8, FormatValue(rfSetListenModeRoutingCmd.UserFields.RoutingEntryList[i].Type, 8), TlvCodingForListenModeRoutingInfo.TlvCodingForListenModeRoutingToString(TlvCodingForListenModeRoutingInfo.ValueToTlvCodingForListenModeRouting(rfSetListenModeRoutingCmd.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(rfSetListenModeRoutingCmd.UserFields.RoutingEntryList[i].Length, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Value[" + i + "]", "Value of the Routing TLV.", rfSetListenModeRoutingCmd.UserFields.RoutingEntryList[i].ValueList.Count * 8, FormatValue(rfSetListenModeRoutingCmd.UserFields.RoutingEntryList[i].ValueList, rfSetListenModeRoutingCmd.UserFields.RoutingEntryList[i].ValueList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

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