using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class CoreGetConfigRspInfo : PacketInfoBase
{
	public override string Name => "Core Get Config Rsp";

	public override string DisplayGroup => "NCI Core";

	public CoreGetConfigRspInfo(CoreGetConfigRsp packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CoreGetConfigRsp coreGetConfigRsp = (CoreGetConfigRsp)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", StatusCodesInfo.StatusCodesToDescription(), 8, FormatValue(coreGetConfigRsp.UserFields.Status, 8), StatusCodesInfo.StatusCodesToString(StatusCodesInfo.ValueToStatusCodes(coreGetConfigRsp.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number of Parameters", "The number of Parameter fields to follow (n).", 8, FormatValue(coreGetConfigRsp.UserFields.NumberOfParameters, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < coreGetConfigRsp.UserFields.ParameterList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("ID[" + i + "]", ConfigurationParameterTagsInfo.ConfigurationParameterTagsToDescription(), 8, FormatValue(coreGetConfigRsp.UserFields.ParameterList[i].Id, 8), ConfigurationParameterTagsInfo.ConfigurationParameterTagsToString(ConfigurationParameterTagsInfo.ValueToConfigurationParameterTags(coreGetConfigRsp.UserFields.ParameterList[i].Id)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Len[" + i + "]", "Length of Val (m). If Len = 0x00, then Val field is omitted.", 8, FormatValue(coreGetConfigRsp.UserFields.ParameterList[i].Len, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Val[" + i + "]", "Value of the configuration parameter.", coreGetConfigRsp.UserFields.ParameterList[i].ValList.Count * 8, FormatValue(coreGetConfigRsp.UserFields.ParameterList[i].ValList, coreGetConfigRsp.UserFields.ParameterList[i].ValList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CoreGetConfigRsp coreGetConfigRsp = (CoreGetConfigRsp)packet;
		int num = -1;
		if (index == ++num)
		{
			coreGetConfigRsp.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			coreGetConfigRsp.UserFields.NumberOfParameters = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < coreGetConfigRsp.UserFields.ParameterList.Count; i++)
		{
			if (index == ++num)
			{
				coreGetConfigRsp.UserFields.ParameterList[i].Id = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				coreGetConfigRsp.UserFields.ParameterList[i].Len = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				value = AddLeadingZerosAndCheckValueStringLength(value, coreGetConfigRsp.UserFields.ParameterList[i].ValList.Count);
				int num2 = 0;
				while (value.Length > 0)
				{
					string value2 = value.Substring(0, 2);
					value = value.Remove(0, 2);
					coreGetConfigRsp.UserFields.ParameterList[i].ValList[num2] = Convert.ToUInt32(value2, 16);
					num2++;
				}
			}
		}
	}
}
