using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class ReadRdsAlternativeFrequencyResponseInfo : PacketInfoBase
{
	public override string Name => "Read Rds Alternative Frequency Response";

	public override string DisplayGroup => "RDS Control";

	public ReadRdsAlternativeFrequencyResponseInfo(ReadRdsAlternativeFrequencyResponse packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ReadRdsAlternativeFrequencyResponse readRdsAlternativeFrequencyResponse = (ReadRdsAlternativeFrequencyResponse)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Undefined 1", "", 7, FormatValue(readRdsAlternativeFrequencyResponse.UserFields.Undefined1, 7), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Frequency Relative To Band", "", 9, FormatValue(readRdsAlternativeFrequencyResponse.UserFields.FrequencyRelativeToBand, 9), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program Identification", "", 16, FormatValue(readRdsAlternativeFrequencyResponse.UserFields.ProgramIdentification, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number Of Alternate Frequencies", "", 8, FormatValue(readRdsAlternativeFrequencyResponse.UserFields.NumberOfAlternateFrequencies, 8), "", "", "19", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < readRdsAlternativeFrequencyResponse.UserFields.AlternateFrequencyListList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Alternate Frequency Code[" + i + "]", "", 8, FormatValue(readRdsAlternativeFrequencyResponse.UserFields.AlternateFrequencyListList[i].AlternateFrequencyCode, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ReadRdsAlternativeFrequencyResponse readRdsAlternativeFrequencyResponse = (ReadRdsAlternativeFrequencyResponse)packet;
		int num = -1;
		if (index == ++num)
		{
			readRdsAlternativeFrequencyResponse.UserFields.Undefined1 = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			readRdsAlternativeFrequencyResponse.UserFields.FrequencyRelativeToBand = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			readRdsAlternativeFrequencyResponse.UserFields.ProgramIdentification = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			readRdsAlternativeFrequencyResponse.UserFields.NumberOfAlternateFrequencies = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < readRdsAlternativeFrequencyResponse.UserFields.AlternateFrequencyListList.Count; i++)
		{
			if (index == ++num)
			{
				readRdsAlternativeFrequencyResponse.UserFields.AlternateFrequencyListList[i].AlternateFrequencyCode = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
