using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class EnableWanAvoidanceControlInfo : PacketInfoBase
{
	public override string Name => "Enable Wan Avoidance Control";

	public override string DisplayGroup => "Receiver Control";

	public EnableWanAvoidanceControlInfo(EnableWanAvoidanceControl packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		EnableWanAvoidanceControl enableWanAvoidanceControl = (EnableWanAvoidanceControl)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Number Of Forbidden Frequencies", "", 8, FormatValue(enableWanAvoidanceControl.UserFields.NumberOfForbiddenFrequencies, 8), "", "", "10", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < enableWanAvoidanceControl.UserFields.ForbiddenFrequencyListList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Forbidden Frequency Index[" + i + "]", "", 8, FormatValue(enableWanAvoidanceControl.UserFields.ForbiddenFrequencyListList[i].ForbiddenFrequencyIndex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("LO Shift[" + i + "]", EnableWanAvoidanceControl.ForbiddenFrequencyListSubField.LoShiftInfo.LoShiftToDescription(), 8, FormatValue(enableWanAvoidanceControl.UserFields.ForbiddenFrequencyListList[i].LoShift, 8), EnableWanAvoidanceControl.ForbiddenFrequencyListSubField.LoShiftInfo.LoShiftToString(EnableWanAvoidanceControl.ForbiddenFrequencyListSubField.LoShiftInfo.ValueToLoShift(enableWanAvoidanceControl.UserFields.ForbiddenFrequencyListList[i].LoShift)), "", "4", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Forbidden Frequency Minimum In kHz[" + i + "]", "", 32, FormatValue(enableWanAvoidanceControl.UserFields.ForbiddenFrequencyListList[i].ForbiddenFrequencyMinimumInKhz, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.DecimalInteger));
			fieldInfoList.Add(new PacketFieldInfo("Forbidden Frequency Maximum In kHz[" + i + "]", "", 32, FormatValue(enableWanAvoidanceControl.UserFields.ForbiddenFrequencyListList[i].ForbiddenFrequencyMaximumInKhz, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		EnableWanAvoidanceControl enableWanAvoidanceControl = (EnableWanAvoidanceControl)packet;
		int num = -1;
		if (index == ++num)
		{
			enableWanAvoidanceControl.UserFields.NumberOfForbiddenFrequencies = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < enableWanAvoidanceControl.UserFields.ForbiddenFrequencyListList.Count; i++)
		{
			if (index == ++num)
			{
				enableWanAvoidanceControl.UserFields.ForbiddenFrequencyListList[i].ForbiddenFrequencyIndex = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				enableWanAvoidanceControl.UserFields.ForbiddenFrequencyListList[i].LoShift = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				enableWanAvoidanceControl.UserFields.ForbiddenFrequencyListList[i].ForbiddenFrequencyMinimumInKhz = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				enableWanAvoidanceControl.UserFields.ForbiddenFrequencyListList[i].ForbiddenFrequencyMaximumInKhz = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
