using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class TxRdsRadioTextInfo : PacketInfoBase
{
	public override string Name => "Tx Rds Radio Text";

	public override string DisplayGroup => "Transmitter Control";

	public TxRdsRadioTextInfo(TxRdsRadioText packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		TxRdsRadioText txRdsRadioText = (TxRdsRadioText)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Radio Text Control", TxRdsRadioText.UserFieldsWrapper.RadioTextControlInfo.RadioTextControlToDescription(), 8, FormatValue(txRdsRadioText.UserFields.RadioTextControl, 8), TxRdsRadioText.UserFieldsWrapper.RadioTextControlInfo.RadioTextControlToString(TxRdsRadioText.UserFieldsWrapper.RadioTextControlInfo.ValueToRadioTextControl(txRdsRadioText.UserFields.RadioTextControl)), "", "2", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program Identification", "The RDS/RBDS program identification", 16, FormatValue(txRdsRadioText.UserFields.ProgramIdentification, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program Type", "The RDS/RBDS program type", 8, FormatValue(txRdsRadioText.UserFields.ProgramType, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Radio Text Length", "The Radio Text Length", 8, FormatValue(txRdsRadioText.UserFields.RadioTextLength, 8), "", "", "40", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Radio Text", "Null terminated Radio Text string up to 64 characters, including the null character", txRdsRadioText.UserFields.RadioTextList.Count * 8, FormatValue(txRdsRadioText.UserFields.RadioTextList, txRdsRadioText.UserFields.RadioTextList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.NullPaddedString));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		TxRdsRadioText txRdsRadioText = (TxRdsRadioText)packet;
		int num = -1;
		if (index == ++num)
		{
			txRdsRadioText.UserFields.RadioTextControl = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			txRdsRadioText.UserFields.ProgramIdentification = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			txRdsRadioText.UserFields.ProgramType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			txRdsRadioText.UserFields.RadioTextLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, txRdsRadioText.UserFields.RadioTextList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				txRdsRadioText.UserFields.RadioTextList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
