using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class SetSpurFilteringTableInfo : PacketInfoBase
{
	public override string Name => "Set Spur Filtering Table";

	public override string DisplayGroup => "Common Control";

	public SetSpurFilteringTableInfo(SetSpurFilteringTable packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SetSpurFilteringTable setSpurFilteringTable = (SetSpurFilteringTable)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Mode", SetSpurFilteringTable.UserFieldsWrapper.ModeInfo.ModeToDescription(), 8, FormatValue(setSpurFilteringTable.UserFields.Mode, 8), SetSpurFilteringTable.UserFieldsWrapper.ModeInfo.ModeToString(SetSpurFilteringTable.UserFieldsWrapper.ModeInfo.ValueToMode(setSpurFilteringTable.UserFields.Mode)), "", "3", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number Of Spur Frequencies To Follow", "Number of frequencies to follow in total, including this command; this is not the number of Spur Entries sent in this command", 8, FormatValue(setSpurFilteringTable.UserFields.NumberOfSpurFrequenciesToFollow, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number Of Spur Entries", "Number of Spur Entry sections in this command", 8, FormatValue(setSpurFilteringTable.UserFields.NumberOfSpurEntries, 8), "", "", "F", settable: true, littleEndianTransport: false, omitFromTransport: true, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < setSpurFilteringTable.UserFields.SpurEntriesList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Spur Frequency[" + i + "]", "Spur frequency", 24, FormatValue(setSpurFilteringTable.UserFields.SpurEntriesList[i].SpurFrequency, 24), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.DecimalInteger));
			fieldInfoList.Add(new PacketFieldInfo("Number Of Spurs To Track[" + i + "]", "Number of spurs to track", 8, FormatValue(setSpurFilteringTable.UserFields.SpurEntriesList[i].NumberOfSpursToTrack, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Spur 0 Entry[" + i + "]", "Spur 0 level and data", 32, FormatValue(setSpurFilteringTable.UserFields.SpurEntriesList[i].Spur0Entry, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Spur 1 Entry[" + i + "]", "Spur 1 level and data", 32, FormatValue(setSpurFilteringTable.UserFields.SpurEntriesList[i].Spur1Entry, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Spur 2 Entry[" + i + "]", "Spur 2 level and data", 32, FormatValue(setSpurFilteringTable.UserFields.SpurEntriesList[i].Spur2Entry, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SetSpurFilteringTable setSpurFilteringTable = (SetSpurFilteringTable)packet;
		int num = -1;
		if (index == ++num)
		{
			setSpurFilteringTable.UserFields.Mode = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			setSpurFilteringTable.UserFields.NumberOfSpurFrequenciesToFollow = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			setSpurFilteringTable.UserFields.NumberOfSpurEntries = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < setSpurFilteringTable.UserFields.SpurEntriesList.Count; i++)
		{
			if (index == ++num)
			{
				setSpurFilteringTable.UserFields.SpurEntriesList[i].SpurFrequency = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				setSpurFilteringTable.UserFields.SpurEntriesList[i].NumberOfSpursToTrack = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				setSpurFilteringTable.UserFields.SpurEntriesList[i].Spur0Entry = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				setSpurFilteringTable.UserFields.SpurEntriesList[i].Spur1Entry = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				setSpurFilteringTable.UserFields.SpurEntriesList[i].Spur2Entry = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
