using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class SetMwsScanFrequencyTableInfo : PacketInfoBase
{
	public override string Name => "Set Mws Scan Frequency Table";

	public override string DisplayGroup => "Host Control and Baseband";

	public SetMwsScanFrequencyTableInfo(SetMwsScanFrequencyTable packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SetMwsScanFrequencyTable setMwsScanFrequencyTable = (SetMwsScanFrequencyTable)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num_Scan_Frequencies", "Number of MWS scan frequencies to be set in the table", 8, FormatValue(setMwsScanFrequencyTable.UserFields.NumScanFrequencies, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < setMwsScanFrequencyTable.UserFields.NumMwsScanFreqList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Scan_Frequency_Low[" + i + "]", "Lower edge of the MWS scan frequency in MHz (unsigned integer).", 16, FormatValue(setMwsScanFrequencyTable.UserFields.NumMwsScanFreqList[i].ScanFrequencyLow, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Scan_Frequency_High[" + i + "]", "Upper edge of the MWS scan frequency in MHz (unsigned integer).", 16, FormatValue(setMwsScanFrequencyTable.UserFields.NumMwsScanFreqList[i].ScanFrequencyHigh, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SetMwsScanFrequencyTable setMwsScanFrequencyTable = (SetMwsScanFrequencyTable)packet;
		int num = -1;
		if (index == ++num)
		{
			setMwsScanFrequencyTable.UserFields.NumScanFrequencies = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < setMwsScanFrequencyTable.UserFields.NumMwsScanFreqList.Count; i++)
		{
			if (index == ++num)
			{
				setMwsScanFrequencyTable.UserFields.NumMwsScanFreqList[i].ScanFrequencyLow = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				setMwsScanFrequencyTable.UserFields.NumMwsScanFreqList[i].ScanFrequencyHigh = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
