using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class CommandCompleteForGetAlternativeRadioFrequencyListInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Get Alternative Radio Frequency List";

	public override string DisplayGroup => "Receiver Control";

	public CommandCompleteForGetAlternativeRadioFrequencyListInfo(CommandCompleteForGetAlternativeRadioFrequencyList packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForGetAlternativeRadioFrequencyList commandCompleteForGetAlternativeRadioFrequencyList = (CommandCompleteForGetAlternativeRadioFrequencyList)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num HCI Command Packets", "", 8, FormatValue(commandCompleteForGetAlternativeRadioFrequencyList.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForGetAlternativeRadioFrequencyList.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForGetAlternativeRadioFrequencyList.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(commandCompleteForGetAlternativeRadioFrequencyList.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(commandCompleteForGetAlternativeRadioFrequencyList.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tune Frequency", "Currently tuned frequency", 32, FormatValue(commandCompleteForGetAlternativeRadioFrequencyList.UserFields.TuneFrequency, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.DecimalInteger));
		fieldInfoList.Add(new PacketFieldInfo("Program Identification Code", "Current Program Identification code", 16, FormatValue(commandCompleteForGetAlternativeRadioFrequencyList.UserFields.ProgramIdentificationCode, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number Of Alternative Frequencies", "", 8, FormatValue(commandCompleteForGetAlternativeRadioFrequencyList.UserFields.NumberOfAlternativeFrequencies, 8), "", "", "19", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < commandCompleteForGetAlternativeRadioFrequencyList.UserFields.AlternativeFrequencyListList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Alternative Frequency[" + i + "]", "Alternative frequency in kHz", 32, FormatValue(commandCompleteForGetAlternativeRadioFrequencyList.UserFields.AlternativeFrequencyListList[i].AlternativeFrequency, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.DecimalInteger));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CommandCompleteForGetAlternativeRadioFrequencyList commandCompleteForGetAlternativeRadioFrequencyList = (CommandCompleteForGetAlternativeRadioFrequencyList)packet;
		int num = -1;
		if (index == ++num)
		{
			commandCompleteForGetAlternativeRadioFrequencyList.UserFields.NumHciCommandPackets = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForGetAlternativeRadioFrequencyList.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			commandCompleteForGetAlternativeRadioFrequencyList.UserFields.TuneFrequency = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			commandCompleteForGetAlternativeRadioFrequencyList.UserFields.ProgramIdentificationCode = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			commandCompleteForGetAlternativeRadioFrequencyList.UserFields.NumberOfAlternativeFrequencies = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < commandCompleteForGetAlternativeRadioFrequencyList.UserFields.AlternativeFrequencyListList.Count; i++)
		{
			if (index == ++num)
			{
				commandCompleteForGetAlternativeRadioFrequencyList.UserFields.AlternativeFrequencyListList[i].AlternativeFrequency = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
