using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class RfDiscoverCmdInfo : PacketInfoBase
{
	public override string Name => "Rf Discover Cmd";

	public override string DisplayGroup => "RF Management";

	public RfDiscoverCmdInfo(RfDiscoverCmd packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RfDiscoverCmd rfDiscoverCmd = (RfDiscoverCmd)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Number of Configurations", "The number of Configuration fields to follow (n). n can be 0 if the RF Discovery is enabled for NFCEE(s) only (e.g. in response to a RF_NFCEE_DISCOVERY_REQ_NTF and an NFCEE(s) providing configuration settings directly to the NFCC). If n is 0, this Command contains no Configuration fields.", 8, FormatValue(rfDiscoverCmd.UserFields.NumberOfConfigurations, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < rfDiscoverCmd.UserFields.ConfigurationList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("RF Technology and Mode[" + i + "]", RfTechnologyAndModeInfo.RfTechnologyAndModeToDescription(), 8, FormatValue(rfDiscoverCmd.UserFields.ConfigurationList[i].RfTechnologyAndMode, 8), RfTechnologyAndModeInfo.RfTechnologyAndModeToString(RfTechnologyAndModeInfo.ValueToRfTechnologyAndMode(rfDiscoverCmd.UserFields.ConfigurationList[i].RfTechnologyAndMode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Discovery Frequency[" + i + "]", RfDiscoverCmd.ConfigurationSubField.DiscoveryFrequencyInfo.DiscoveryFrequencyToDescription(), 8, FormatValue(rfDiscoverCmd.UserFields.ConfigurationList[i].DiscoveryFrequency, 8), RfDiscoverCmd.ConfigurationSubField.DiscoveryFrequencyInfo.DiscoveryFrequencyToString(RfDiscoverCmd.ConfigurationSubField.DiscoveryFrequencyInfo.ValueToDiscoveryFrequency(rfDiscoverCmd.UserFields.ConfigurationList[i].DiscoveryFrequency)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		RfDiscoverCmd rfDiscoverCmd = (RfDiscoverCmd)packet;
		int num = -1;
		if (index == ++num)
		{
			rfDiscoverCmd.UserFields.NumberOfConfigurations = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < rfDiscoverCmd.UserFields.ConfigurationList.Count; i++)
		{
			if (index == ++num)
			{
				rfDiscoverCmd.UserFields.ConfigurationList[i].RfTechnologyAndMode = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				rfDiscoverCmd.UserFields.ConfigurationList[i].DiscoveryFrequency = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
