using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class AudioControlInfo : PacketInfoBase
{
	public override string Name => "Audio Control";

	public override string DisplayGroup => "Control";

	public AudioControlInfo(AudioControl packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		AudioControl audioControl = (AudioControl)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Register Address", RegisterMapInfo.RegisterMapToDescription(), 8, FormatValue(audioControl.UserFields.RegisterAddress, 8), RegisterMapInfo.RegisterMapToString(RegisterMapInfo.ValueToRegisterMap(audioControl.UserFields.RegisterAddress)), "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Unused", "", 3, FormatValue(audioControl.UserFields.Unused, 3), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RX To Bluetooth", AudioControl.UserFieldsWrapper.RxToBluetoothInfo.RxToBluetoothToDescription(), 1, FormatValue(audioControl.UserFields.RxToBluetooth, 1), AudioControl.UserFieldsWrapper.RxToBluetoothInfo.RxToBluetoothToString(AudioControl.UserFieldsWrapper.RxToBluetoothInfo.ValueToRxToBluetooth(audioControl.UserFields.RxToBluetooth)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("I2S Control", AudioControl.UserFieldsWrapper.I2sControlInfo.I2sControlToDescription(), 1, FormatValue(audioControl.UserFields.I2sControl, 1), AudioControl.UserFieldsWrapper.I2sControlInfo.I2sControlToString(AudioControl.UserFieldsWrapper.I2sControlInfo.ValueToI2sControl(audioControl.UserFields.I2sControl)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Audio TX", AudioControl.UserFieldsWrapper.AudioTxInfo.AudioTxToDescription(), 1, FormatValue(audioControl.UserFields.AudioTx, 1), AudioControl.UserFieldsWrapper.AudioTxInfo.AudioTxToString(AudioControl.UserFieldsWrapper.AudioTxInfo.ValueToAudioTx(audioControl.UserFields.AudioTx)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Audio RX", AudioControl.UserFieldsWrapper.AudioRxInfo.AudioRxToDescription(), 2, FormatValue(audioControl.UserFields.AudioRx, 2), AudioControl.UserFieldsWrapper.AudioRxInfo.AudioRxToString(AudioControl.UserFieldsWrapper.AudioRxInfo.ValueToAudioRx(audioControl.UserFields.AudioRx)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		AudioControl audioControl = (AudioControl)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field RegisterAddress");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field Unused");
		}
		if (index == ++num)
		{
			audioControl.UserFields.RxToBluetooth = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			audioControl.UserFields.I2sControl = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			audioControl.UserFields.AudioTx = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			audioControl.UserFields.AudioRx = Convert.ToUInt32(value, 16);
		}
	}
}
