using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FM.Packets;

public class ReadRdsRadioTextResponseInfo : PacketInfoBase
{
	public override string Name => "Read Rds Radio Text Response";

	public override string DisplayGroup => "RDS Control";

	public ReadRdsRadioTextResponseInfo(ReadRdsRadioTextResponse packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		ReadRdsRadioTextResponse readRdsRadioTextResponse = (ReadRdsRadioTextResponse)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Length", "Length of radio text string", 8, FormatValue(readRdsRadioTextResponse.UserFields.Length, 8), "", "", "40", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TX Control", ReadRdsRadioTextResponse.UserFieldsWrapper.TxControlInfo.TxControlToDescription(), 1, FormatValue(readRdsRadioTextResponse.UserFields.TxControl, 1), ReadRdsRadioTextResponse.UserFieldsWrapper.TxControlInfo.TxControlToString(ReadRdsRadioTextResponse.UserFieldsWrapper.TxControlInfo.ValueToTxControl(readRdsRadioTextResponse.UserFields.TxControl)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Undefined 1", "", 2, FormatValue(readRdsRadioTextResponse.UserFields.Undefined1, 2), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program Type", "RDS program type\r\n\r\n" + ProgramTypeInfo.ProgramTypeToDescription(), 5, FormatValue(readRdsRadioTextResponse.UserFields.ProgramType, 5), ProgramTypeInfo.ProgramTypeToString(ProgramTypeInfo.ValueToProgramType(readRdsRadioTextResponse.UserFields.ProgramType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program Identification", "Program identification code", 16, FormatValue(readRdsRadioTextResponse.UserFields.ProgramIdentification, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Undefined 2", "", 6, FormatValue(readRdsRadioTextResponse.UserFields.Undefined2, 6), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Text AB Flag", "Text A/B flag", 1, FormatValue(readRdsRadioTextResponse.UserFields.TextAbFlag, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Traffic Program Code", "Traffic program code", 1, FormatValue(readRdsRadioTextResponse.UserFields.TrafficProgramCode, 1), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Radio Text", "Radio text", readRdsRadioTextResponse.UserFields.RadioTextList.Count * 8, FormatValue(readRdsRadioTextResponse.UserFields.RadioTextList, readRdsRadioTextResponse.UserFields.RadioTextList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.NullPaddedString));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		ReadRdsRadioTextResponse readRdsRadioTextResponse = (ReadRdsRadioTextResponse)packet;
		int num = -1;
		if (index == ++num)
		{
			readRdsRadioTextResponse.UserFields.Length = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readRdsRadioTextResponse.UserFields.TxControl = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readRdsRadioTextResponse.UserFields.Undefined1 = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readRdsRadioTextResponse.UserFields.ProgramType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readRdsRadioTextResponse.UserFields.ProgramIdentification = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readRdsRadioTextResponse.UserFields.Undefined2 = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readRdsRadioTextResponse.UserFields.TextAbFlag = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			readRdsRadioTextResponse.UserFields.TrafficProgramCode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, readRdsRadioTextResponse.UserFields.RadioTextList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				readRdsRadioTextResponse.UserFields.RadioTextList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
