using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class TxRdsProgramServiceInfo : PacketInfoBase
{
	public override string Name => "Tx Rds Program Service";

	public override string DisplayGroup => "Transmitter Control";

	public TxRdsProgramServiceInfo(TxRdsProgramService packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		TxRdsProgramService txRdsProgramService = (TxRdsProgramService)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Program Service Control", TxRdsProgramService.UserFieldsWrapper.ProgramServiceControlInfo.ProgramServiceControlToDescription(), 8, FormatValue(txRdsProgramService.UserFields.ProgramServiceControl, 8), TxRdsProgramService.UserFieldsWrapper.ProgramServiceControlInfo.ProgramServiceControlToString(TxRdsProgramService.UserFieldsWrapper.ProgramServiceControlInfo.ValueToProgramServiceControl(txRdsProgramService.UserFields.ProgramServiceControl)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program Identification", "The RDS/RBDS program identification", 16, FormatValue(txRdsProgramService.UserFields.ProgramIdentification, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program Type", "The RDS/RBDS program type", 8, FormatValue(txRdsProgramService.UserFields.ProgramType, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Repeat Count", "Repeat count for each string to be transmitted", 8, FormatValue(txRdsProgramService.UserFields.RepeatCount, 8), "", "", "F", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number Of Valid Program Service Strings", "", 8, FormatValue(txRdsProgramService.UserFields.NumberOfValidProgramServiceStrings, 8), "", "", "C", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < txRdsProgramService.UserFields.ProgramServiceNameList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Name String[" + i + "]", "", 64, FormatValue(txRdsProgramService.UserFields.ProgramServiceNameList[i].NameString, 64), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Null Terminator[" + i + "]", "", 8, FormatValue(txRdsProgramService.UserFields.ProgramServiceNameList[i].NullTerminator, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		TxRdsProgramService txRdsProgramService = (TxRdsProgramService)packet;
		int num = -1;
		if (index == ++num)
		{
			txRdsProgramService.UserFields.ProgramServiceControl = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			txRdsProgramService.UserFields.ProgramIdentification = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			txRdsProgramService.UserFields.ProgramType = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			txRdsProgramService.UserFields.RepeatCount = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			txRdsProgramService.UserFields.NumberOfValidProgramServiceStrings = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < txRdsProgramService.UserFields.ProgramServiceNameList.Count; i++)
		{
			if (index == ++num)
			{
				txRdsProgramService.UserFields.ProgramServiceNameList[i].NameString = Convert.ToUInt64(value, 16);
				break;
			}
			if (index == ++num)
			{
				txRdsProgramService.UserFields.ProgramServiceNameList[i].NullTerminator = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
