using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class ReadRdsProgramServiceResponseInfo : PacketInfoBase
{
	public override string Name => "Read Rds Program Service Response";

	public override string DisplayGroup => "RDS Control";

	public ReadRdsProgramServiceResponseInfo(ReadRdsProgramServiceResponse packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ReadRdsProgramServiceResponse readRdsProgramServiceResponse = (ReadRdsProgramServiceResponse)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Decoder Information", "", 1, FormatValue(readRdsProgramServiceResponse.UserFields.DecoderInformation, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Music Speech Switch", "", 1, FormatValue(readRdsProgramServiceResponse.UserFields.MusicSpeechSwitch, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Traffic Announcement", "", 1, FormatValue(readRdsProgramServiceResponse.UserFields.TrafficAnnouncement, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Traffic Program", "", 1, FormatValue(readRdsProgramServiceResponse.UserFields.TrafficProgram, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number Of Program Service Names", "", 4, FormatValue(readRdsProgramServiceResponse.UserFields.NumberOfProgramServiceNames, 4), "", "", "0C", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Undefined 1", "", 4, FormatValue(readRdsProgramServiceResponse.UserFields.Undefined1, 4), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program Type", "RDS program type\r\n\r\n" + ProgramTypeInfo.ProgramTypeToDescription(), 4, FormatValue(readRdsProgramServiceResponse.UserFields.ProgramType, 4), ProgramTypeInfo.ProgramTypeToString(ProgramTypeInfo.ValueToProgramType(readRdsProgramServiceResponse.UserFields.ProgramType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program Identification", "Program identification code", 16, FormatValue(readRdsProgramServiceResponse.UserFields.ProgramIdentification, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TX Control", "", 1, FormatValue(readRdsProgramServiceResponse.UserFields.TxControl, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Undefined 2", "", 3, FormatValue(readRdsProgramServiceResponse.UserFields.Undefined2, 3), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TX Repeat", "Number of times to repeat each Program Service name", 4, FormatValue(readRdsProgramServiceResponse.UserFields.TxRepeat, 4), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < readRdsProgramServiceResponse.UserFields.ProgramServiceNamesList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Program Service Name[" + i + "]", "", 64, FormatValue(readRdsProgramServiceResponse.UserFields.ProgramServiceNamesList[i].ProgramServiceName, 64), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ReadRdsProgramServiceResponse readRdsProgramServiceResponse = (ReadRdsProgramServiceResponse)packet;
		int num = -1;
		if (index == ++num)
		{
			readRdsProgramServiceResponse.UserFields.DecoderInformation = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			readRdsProgramServiceResponse.UserFields.MusicSpeechSwitch = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			readRdsProgramServiceResponse.UserFields.TrafficAnnouncement = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			readRdsProgramServiceResponse.UserFields.TrafficProgram = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			readRdsProgramServiceResponse.UserFields.NumberOfProgramServiceNames = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			readRdsProgramServiceResponse.UserFields.Undefined1 = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			readRdsProgramServiceResponse.UserFields.ProgramType = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			readRdsProgramServiceResponse.UserFields.ProgramIdentification = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			readRdsProgramServiceResponse.UserFields.TxControl = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			readRdsProgramServiceResponse.UserFields.Undefined2 = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			readRdsProgramServiceResponse.UserFields.TxRepeat = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < readRdsProgramServiceResponse.UserFields.ProgramServiceNamesList.Count; i++)
		{
			if (index == ++num)
			{
				readRdsProgramServiceResponse.UserFields.ProgramServiceNamesList[i].ProgramServiceName = Convert.ToUInt64(value, 16);
				break;
			}
		}
	}
}
