using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class TxTestInfo : PacketInfoBase
{
	public override string Name => "Tx Test";

	public override string DisplayGroup => "Production Test Mode";

	public TxTestInfo(TxTest packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		TxTest txTest = (TxTest)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Enable RDS", TxTest.UserFieldsWrapper.EnableRdsInfo.EnableRdsToDescription(), 8, FormatValue(txTest.UserFields.EnableRds, 8), TxTest.UserFieldsWrapper.EnableRdsInfo.EnableRdsToString(TxTest.UserFieldsWrapper.EnableRdsInfo.ValueToEnableRds(txTest.UserFields.EnableRds)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Pre Emphasis", TxTest.UserFieldsWrapper.PreEmphasisInfo.PreEmphasisToDescription(), 8, FormatValue(txTest.UserFields.PreEmphasis, 8), TxTest.UserFieldsWrapper.PreEmphasisInfo.PreEmphasisToString(TxTest.UserFieldsWrapper.PreEmphasisInfo.ValueToPreEmphasis(txTest.UserFields.PreEmphasis)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Stereo", TxTest.UserFieldsWrapper.StereoInfo.StereoToDescription(), 8, FormatValue(txTest.UserFields.Stereo, 8), TxTest.UserFieldsWrapper.StereoInfo.StereoToString(TxTest.UserFieldsWrapper.StereoInfo.ValueToStereo(txTest.UserFields.Stereo)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Enable Pre Emphasis", TxTest.UserFieldsWrapper.EnablePreEmphasisInfo.EnablePreEmphasisToDescription(), 8, FormatValue(txTest.UserFields.EnablePreEmphasis, 8), TxTest.UserFieldsWrapper.EnablePreEmphasisInfo.EnablePreEmphasisToString(TxTest.UserFieldsWrapper.EnablePreEmphasisInfo.ValueToEnablePreEmphasis(txTest.UserFields.EnablePreEmphasis)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tune Frequency", "Frequency to tune in kHz", 32, FormatValue(txTest.UserFields.TuneFrequency, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.DecimalInteger));
		fieldInfoList.Add(new PacketFieldInfo("Modulation Multiplier For Stereo", "Modulation multiplier for stereo (0x80 = 42.75%)", 8, FormatValue(txTest.UserFields.ModulationMultiplierForStereo, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Modulation Multiplier For Pilot", "Modulation multiplier for 19 kHz pilot (0x80 = 9.5%)", 8, FormatValue(txTest.UserFields.ModulationMultiplierForPilot, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Modulation Multiplier For RDS", "Modulation multiplier for RDS (0x80 = 9.5%)", 8, FormatValue(txTest.UserFields.ModulationMultiplierForRds, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Modulation Multiplier For Mono", "Modulation multiplier for Mono (L+R) (0x80 = 42.75%)", 8, FormatValue(txTest.UserFields.ModulationMultiplierForMono, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		TxTest txTest = (TxTest)packet;
		int num = -1;
		if (index == ++num)
		{
			txTest.UserFields.EnableRds = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			txTest.UserFields.PreEmphasis = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			txTest.UserFields.Stereo = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			txTest.UserFields.EnablePreEmphasis = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			txTest.UserFields.TuneFrequency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			txTest.UserFields.ModulationMultiplierForStereo = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			txTest.UserFields.ModulationMultiplierForPilot = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			txTest.UserFields.ModulationMultiplierForRds = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			txTest.UserFields.ModulationMultiplierForMono = Convert.ToUInt32(value, 16);
		}
	}
}
