using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class CommandCompleteForGetRadioTextInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Get Radio Text";

	public override string DisplayGroup => "Receiver Control";

	public CommandCompleteForGetRadioTextInfo(CommandCompleteForGetRadioText packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForGetRadioText commandCompleteForGetRadioText = (CommandCompleteForGetRadioText)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num HCI Command Packets", "", 8, FormatValue(commandCompleteForGetRadioText.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForGetRadioText.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForGetRadioText.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(commandCompleteForGetRadioText.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(commandCompleteForGetRadioText.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program Identification", "The RDS/RBDS program identification", 16, FormatValue(commandCompleteForGetRadioText.UserFields.ProgramIdentification, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Program Type", "The RDS/RBDS program type", 8, FormatValue(commandCompleteForGetRadioText.UserFields.ProgramType, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Traffic Program Code Flag", CommandCompleteForGetRadioText.UserFieldsWrapper.TrafficProgramCodeFlagInfo.TrafficProgramCodeFlagToDescription(), 8, FormatValue(commandCompleteForGetRadioText.UserFields.TrafficProgramCodeFlag, 8), CommandCompleteForGetRadioText.UserFieldsWrapper.TrafficProgramCodeFlagInfo.TrafficProgramCodeFlagToString(CommandCompleteForGetRadioText.UserFieldsWrapper.TrafficProgramCodeFlagInfo.ValueToTrafficProgramCodeFlag(commandCompleteForGetRadioText.UserFields.TrafficProgramCodeFlag)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Text A B Flag", CommandCompleteForGetRadioText.UserFieldsWrapper.TextABFlagInfo.TextABFlagToDescription(), 8, FormatValue(commandCompleteForGetRadioText.UserFields.TextABFlag, 8), CommandCompleteForGetRadioText.UserFieldsWrapper.TextABFlagInfo.TextABFlagToString(CommandCompleteForGetRadioText.UserFieldsWrapper.TextABFlagInfo.ValueToTextABFlag(commandCompleteForGetRadioText.UserFields.TextABFlag)), "", "1", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Radio Text Length", "", 8, FormatValue(commandCompleteForGetRadioText.UserFields.RadioTextLength, 8), "", "", "40", settable: true, littleEndianTransport: false, omitFromTransport: true, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Radio Text", "", commandCompleteForGetRadioText.UserFields.RadioTextList.Count * 8, FormatValue(commandCompleteForGetRadioText.UserFields.RadioTextList, commandCompleteForGetRadioText.UserFields.RadioTextList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.NullPaddedString));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CommandCompleteForGetRadioText commandCompleteForGetRadioText = (CommandCompleteForGetRadioText)packet;
		int num = -1;
		if (index == ++num)
		{
			commandCompleteForGetRadioText.UserFields.NumHciCommandPackets = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForGetRadioText.UserFields.Status = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForGetRadioText.UserFields.ProgramIdentification = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForGetRadioText.UserFields.ProgramType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForGetRadioText.UserFields.TrafficProgramCodeFlag = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForGetRadioText.UserFields.TextABFlag = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForGetRadioText.UserFields.RadioTextLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, commandCompleteForGetRadioText.UserFields.RadioTextList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				commandCompleteForGetRadioText.UserFields.RadioTextList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
