using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class RfParameterUpdateCmdInfo : PacketInfoBase
{
	public override string Name => "Rf Parameter Update Cmd";

	public override string DisplayGroup => "RF Management";

	public RfParameterUpdateCmdInfo(RfParameterUpdateCmd packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RfParameterUpdateCmd rfParameterUpdateCmd = (RfParameterUpdateCmd)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Number of Parameters", "The number of RF Communication Parameter fields to follow (n).", 8, FormatValue(rfParameterUpdateCmd.UserFields.NumberOfParameters, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < rfParameterUpdateCmd.UserFields.RfCommunicationParameterList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("ID[" + i + "]", RfParameterUpdateCmd.RfCommunicationParameterSubField.IdInfo.IdToDescription(), 8, FormatValue(rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].Id, 8), RfParameterUpdateCmd.RfCommunicationParameterSubField.IdInfo.IdToString(RfParameterUpdateCmd.RfCommunicationParameterSubField.IdInfo.ValueToId(rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].Id)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Length[" + i + "]", "The length of Value (x).", 8, FormatValue(rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].Length, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			if (rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList.Count > 0 && rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList.Count <= 4)
			{
				if (rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].Id == 0)
				{
					fieldInfoList.Add(new PacketFieldInfo("Value[" + i + "]", "Value of the RF Communication Parameter.\r\n\r\n" + RfTechnologyAndModeInfo.RfTechnologyAndModeToDescription(), rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList.Count * 8, FormatValue(rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList, rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList.Count * 8, includeSpaces: false), RfTechnologyAndModeInfo.RfTechnologyAndModeToString(RfTechnologyAndModeInfo.ValueToRfTechnologyAndMode(Conversions.UintListToUint(rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList))), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
				}
				else if (rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].Id >= 1 && rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].Id <= 2)
				{
					fieldInfoList.Add(new PacketFieldInfo("Value[" + i + "]", "Value of the RF Communication Parameter.\r\n\r\n" + BitRatesInfo.BitRatesToDescription(), rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList.Count * 8, FormatValue(rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList, rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList.Count * 8, includeSpaces: false), BitRatesInfo.BitRatesToString(BitRatesInfo.ValueToBitRates(Conversions.UintListToUint(rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList))), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
				}
				else if (rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].Id == 3)
				{
					fieldInfoList.Add(new PacketFieldInfo("Value[" + i + "]", "Value of the RF Communication Parameter.\r\n\r\n" + NfcbDataExchangeConfigurationInfo.NfcbDataExchangeConfigurationToDescription(), rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList.Count * 8, FormatValue(rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList, rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList.Count * 8, includeSpaces: false), NfcbDataExchangeConfigurationInfo.NfcbDataExchangeConfigurationToString(NfcbDataExchangeConfigurationInfo.ValueToNfcbDataExchangeConfiguration(Conversions.UintListToUint(rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList))), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
				}
				else
				{
					fieldInfoList.Add(new PacketFieldInfo("Value[" + i + "]", "Value of the RF Communication Parameter.", rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList.Count * 8, FormatValue(rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList, rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
				}
			}
			else
			{
				fieldInfoList.Add(new PacketFieldInfo("Value[" + i + "]", "Value of the RF Communication Parameter.", rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList.Count * 8, FormatValue(rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList, rfParameterUpdateCmd.UserFields.RfCommunicationParameterList[i].ValueList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			}
		}
	}

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