using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class RadioTextInfo : PacketInfoBase
{
	public override string Name => "Radio Text";

	public override string DisplayGroup => "Events";

	public RadioTextInfo(RadioText packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		RadioText radioText = (RadioText)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Program Identification", "The RDS/RBDS program identification", 16, FormatValue(radioText.UserFields.ProgramIdentification, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program Type", "The RDS/RBDS program type", 8, FormatValue(radioText.UserFields.ProgramType, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Traffic Program Code Flag", RadioText.UserFieldsWrapper.TrafficProgramCodeFlagInfo.TrafficProgramCodeFlagToDescription(), 8, FormatValue(radioText.UserFields.TrafficProgramCodeFlag, 8), RadioText.UserFieldsWrapper.TrafficProgramCodeFlagInfo.TrafficProgramCodeFlagToString(RadioText.UserFieldsWrapper.TrafficProgramCodeFlagInfo.ValueToTrafficProgramCodeFlag(radioText.UserFields.TrafficProgramCodeFlag)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Text A B Flag", RadioText.UserFieldsWrapper.TextABFlagInfo.TextABFlagToDescription(), 8, FormatValue(radioText.UserFields.TextABFlag, 8), RadioText.UserFieldsWrapper.TextABFlagInfo.TextABFlagToString(RadioText.UserFieldsWrapper.TextABFlagInfo.ValueToTextABFlag(radioText.UserFields.TextABFlag)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Radio Text Length", "", 8, FormatValue(radioText.UserFields.RadioTextLength, 8), "", "", "40", settable: true, littleEndianTransport: false, omitFromTransport: true, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Radio Text", "", radioText.UserFields.RadioTextList.Count * 8, FormatValue(radioText.UserFields.RadioTextList, radioText.UserFields.RadioTextList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.NullPaddedString));
	}

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