using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class ToneConfigurationInfo : PacketInfoBase
{
	public override string Name => "Tone Configuration";

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

	public ToneConfigurationInfo(ToneConfiguration packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ToneConfiguration toneConfiguration = (ToneConfiguration)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Left Channel Control", ToneConfiguration.UserFieldsWrapper.LeftChannelControlInfo.LeftChannelControlToDescription(), 8, FormatValue(toneConfiguration.UserFields.LeftChannelControl, 8), ToneConfiguration.UserFieldsWrapper.LeftChannelControlInfo.LeftChannelControlToString(ToneConfiguration.UserFieldsWrapper.LeftChannelControlInfo.ValueToLeftChannelControl(toneConfiguration.UserFields.LeftChannelControl)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Right Channel Control", ToneConfiguration.UserFieldsWrapper.RightChannelControlInfo.RightChannelControlToDescription(), 8, FormatValue(toneConfiguration.UserFields.RightChannelControl, 8), ToneConfiguration.UserFieldsWrapper.RightChannelControlInfo.RightChannelControlToString(ToneConfiguration.UserFieldsWrapper.RightChannelControlInfo.ValueToRightChannelControl(toneConfiguration.UserFields.RightChannelControl)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tone Scaling Factor Index", "", 8, FormatValue(toneConfiguration.UserFields.ToneScalingFactorIndex, 8), "", "", "C", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Left Channel Frequency", "Left Channel Output Frequency (in kHz)", 8, FormatValue(toneConfiguration.UserFields.LeftChannelFrequency, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.DecimalInteger));
		fieldInfoList.Add(new PacketFieldInfo("Right Channel Frequency", "Right Channel Output Frequency (in kHz)", 8, FormatValue(toneConfiguration.UserFields.RightChannelFrequency, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.DecimalInteger));
		fieldInfoList.Add(new PacketFieldInfo("Left Channel Phase", "Left Channel Output Phase (in 7.5 degree steps)", 8, FormatValue(toneConfiguration.UserFields.LeftChannelPhase, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Right Channel Phase", "Right Channel Output Frequency (in 7.5 degree steps)", 8, FormatValue(toneConfiguration.UserFields.RightChannelPhase, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ToneConfiguration toneConfiguration = (ToneConfiguration)packet;
		int num = -1;
		if (index == ++num)
		{
			toneConfiguration.UserFields.LeftChannelControl = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			toneConfiguration.UserFields.RightChannelControl = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			toneConfiguration.UserFields.ToneScalingFactorIndex = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			toneConfiguration.UserFields.LeftChannelFrequency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			toneConfiguration.UserFields.RightChannelFrequency = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			toneConfiguration.UserFields.LeftChannelPhase = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			toneConfiguration.UserFields.RightChannelPhase = Convert.ToUInt32(value, 16);
		}
	}
}
