using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

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

	public override string DisplayGroup => "RF Management";

	public RfDiscoverMapCmdInfo(RfDiscoverMapCmd packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RfDiscoverMapCmd rfDiscoverMapCmd = (RfDiscoverMapCmd)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Number of Mapping Configurations", "The number of Mapping Configuration fields to follow (n).", 8, FormatValue(rfDiscoverMapCmd.UserFields.NumberOfMappingConfigurations, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < rfDiscoverMapCmd.UserFields.MappingConfigurationList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("RF Protocol[" + i + "]", RfProtocolsInfo.RfProtocolsToDescription(), 8, FormatValue(rfDiscoverMapCmd.UserFields.MappingConfigurationList[i].RfProtocol, 8), RfProtocolsInfo.RfProtocolsToString(RfProtocolsInfo.ValueToRfProtocols(rfDiscoverMapCmd.UserFields.MappingConfigurationList[i].RfProtocol)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Mode[" + i + "]", RfDiscoverMapCmd.MappingConfigurationSubField.ModeInfo.ModeToDescription(), 8, FormatValue(rfDiscoverMapCmd.UserFields.MappingConfigurationList[i].Mode, 8), RfDiscoverMapCmd.MappingConfigurationSubField.ModeInfo.ModeToString(RfDiscoverMapCmd.MappingConfigurationSubField.ModeInfo.ValueToMode(rfDiscoverMapCmd.UserFields.MappingConfigurationList[i].Mode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("RF Interface[" + i + "]", RfInterfacesInfo.RfInterfacesToDescription(), 8, FormatValue(rfDiscoverMapCmd.UserFields.MappingConfigurationList[i].RfInterface, 8), RfInterfacesInfo.RfInterfacesToString(RfInterfacesInfo.ValueToRfInterfaces(rfDiscoverMapCmd.UserFields.MappingConfigurationList[i].RfInterface)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		RfDiscoverMapCmd rfDiscoverMapCmd = (RfDiscoverMapCmd)packet;
		int num = -1;
		if (index == ++num)
		{
			rfDiscoverMapCmd.UserFields.NumberOfMappingConfigurations = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < rfDiscoverMapCmd.UserFields.MappingConfigurationList.Count; i++)
		{
			if (index == ++num)
			{
				rfDiscoverMapCmd.UserFields.MappingConfigurationList[i].RfProtocol = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				rfDiscoverMapCmd.UserFields.MappingConfigurationList[i].Mode = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				rfDiscoverMapCmd.UserFields.MappingConfigurationList[i].RfInterface = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
