using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class SetChannelDetectionThresholdsInfo : PacketInfoBase
{
	public override string Name => "Set Channel Detection Thresholds";

	public override string DisplayGroup => "Receiver Control";

	public SetChannelDetectionThresholdsInfo(SetChannelDetectionThresholds packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		SetChannelDetectionThresholds setChannelDetectionThresholds = (SetChannelDetectionThresholds)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Acquisition Threshold", "SINR Acquisition Threshold (signed, -128 [0x80] to 127 [0x7F])", 8, FormatValue(setChannelDetectionThresholds.UserFields.AcquisitionThreshold, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number Of Samples", "The number of SINR samples to average", 8, FormatValue(setChannelDetectionThresholds.UserFields.NumberOfSamples, 8), "", "1", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Interference Detector Output Threshold Low", "", 8, FormatValue(setChannelDetectionThresholds.UserFields.InterferenceDetectorOutputThresholdLow, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Interference Detector Output Threshold High", "", 8, FormatValue(setChannelDetectionThresholds.UserFields.InterferenceDetectorOutputThresholdHigh, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		SetChannelDetectionThresholds setChannelDetectionThresholds = (SetChannelDetectionThresholds)packet;
		int num = -1;
		if (index == ++num)
		{
			setChannelDetectionThresholds.UserFields.AcquisitionThreshold = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setChannelDetectionThresholds.UserFields.NumberOfSamples = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setChannelDetectionThresholds.UserFields.InterferenceDetectorOutputThresholdLow = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			setChannelDetectionThresholds.UserFields.InterferenceDetectorOutputThresholdHigh = Convert.ToUInt32(value, 16);
		}
	}
}
