using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class IoControlInfo : PacketInfoBase
{
	public override string Name => "Io Control";

	public override string DisplayGroup => "Control";

	public IoControlInfo(IoControl packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		IoControl ioControl = (IoControl)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Register Address", RegisterMapInfo.RegisterMapToDescription(), 8, FormatValue(ioControl.UserFields.RegisterAddress, 8), RegisterMapInfo.RegisterMapToString(RegisterMapInfo.ValueToRegisterMap(ioControl.UserFields.RegisterAddress)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Mono Stereo Switch", IoControl.UserFieldsWrapper.MonoStereoSwitchInfo.MonoStereoSwitchToDescription(), 1, FormatValue(ioControl.UserFields.MonoStereoSwitch, 1), IoControl.UserFieldsWrapper.MonoStereoSwitchInfo.MonoStereoSwitchToString(IoControl.UserFieldsWrapper.MonoStereoSwitchInfo.ValueToMonoStereoSwitch(ioControl.UserFields.MonoStereoSwitch)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Antenna", IoControl.UserFieldsWrapper.AntennaInfo.AntennaToDescription(), 1, FormatValue(ioControl.UserFields.Antenna, 1), IoControl.UserFieldsWrapper.AntennaInfo.AntennaToString(IoControl.UserFieldsWrapper.AntennaInfo.ValueToAntenna(ioControl.UserFields.Antenna)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Interference Blending", IoControl.UserFieldsWrapper.InterferenceBlendingInfo.InterferenceBlendingToDescription(), 1, FormatValue(ioControl.UserFields.InterferenceBlending, 1), IoControl.UserFieldsWrapper.InterferenceBlendingInfo.InterferenceBlendingToString(IoControl.UserFieldsWrapper.InterferenceBlendingInfo.ValueToInterferenceBlending(ioControl.UserFields.InterferenceBlending)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Signal Blending", IoControl.UserFieldsWrapper.SignalBlendingInfo.SignalBlendingToDescription(), 1, FormatValue(ioControl.UserFields.SignalBlending, 1), IoControl.UserFieldsWrapper.SignalBlendingInfo.SignalBlendingToString(IoControl.UserFieldsWrapper.SignalBlendingInfo.ValueToSignalBlending(ioControl.UserFields.SignalBlending)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Mono Stereo Mode", IoControl.UserFieldsWrapper.MonoStereoModeInfo.MonoStereoModeToDescription(), 1, FormatValue(ioControl.UserFields.MonoStereoMode, 1), IoControl.UserFieldsWrapper.MonoStereoModeInfo.MonoStereoModeToString(IoControl.UserFieldsWrapper.MonoStereoModeInfo.ValueToMonoStereoMode(ioControl.UserFields.MonoStereoMode)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Soft Mute", IoControl.UserFieldsWrapper.SoftMuteInfo.SoftMuteToDescription(), 1, FormatValue(ioControl.UserFields.SoftMute, 1), IoControl.UserFieldsWrapper.SoftMuteInfo.SoftMuteToString(IoControl.UserFieldsWrapper.SoftMuteInfo.ValueToSoftMute(ioControl.UserFields.SoftMute)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Hard Mute", IoControl.UserFieldsWrapper.HardMuteInfo.HardMuteToDescription(), 2, FormatValue(ioControl.UserFields.HardMute, 2), IoControl.UserFieldsWrapper.HardMuteInfo.HardMuteToString(IoControl.UserFieldsWrapper.HardMuteInfo.ValueToHardMute(ioControl.UserFields.HardMute)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		IoControl ioControl = (IoControl)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field RegisterAddress");
		}
		if (index == ++num)
		{
			ioControl.UserFields.MonoStereoSwitch = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			ioControl.UserFields.Antenna = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			ioControl.UserFields.InterferenceBlending = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			ioControl.UserFields.SignalBlending = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			ioControl.UserFields.MonoStereoMode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			ioControl.UserFields.SoftMute = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			ioControl.UserFields.HardMute = Convert.ToUInt32(value, 16);
		}
	}
}
