using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class CoreConnCreateCmdInfo : PacketInfoBase
{
	public override string Name => "Core Conn Create Cmd";

	public override string DisplayGroup => "NCI Core";

	public CoreConnCreateCmdInfo(CoreConnCreateCmd packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CoreConnCreateCmd coreConnCreateCmd = (CoreConnCreateCmd)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Destination Type", CoreConnCreateCmd.UserFieldsWrapper.DestinationTypeInfo.DestinationTypeToDescription(), 8, FormatValue(coreConnCreateCmd.UserFields.DestinationType, 8), CoreConnCreateCmd.UserFieldsWrapper.DestinationTypeInfo.DestinationTypeToString(CoreConnCreateCmd.UserFieldsWrapper.DestinationTypeInfo.ValueToDestinationType(coreConnCreateCmd.UserFields.DestinationType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number of Destination-specific Parameters", "Based on the Destination Type of the connection, the number of Destination-specific Parameter fields following (n).", 8, FormatValue(coreConnCreateCmd.UserFields.NumberOfDestinationSpecificParameters, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < coreConnCreateCmd.UserFields.DestinationSpecificParameterList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Type[" + i + "]", CoreConnCreateCmd.DestinationSpecificParameterSubField.TypeInfo.TypeToDescription(), 8, FormatValue(coreConnCreateCmd.UserFields.DestinationSpecificParameterList[i].Type, 8), CoreConnCreateCmd.DestinationSpecificParameterSubField.TypeInfo.TypeToString(CoreConnCreateCmd.DestinationSpecificParameterSubField.TypeInfo.ValueToType(coreConnCreateCmd.UserFields.DestinationSpecificParameterList[i].Type)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Length[" + i + "]", "Length of Value (m).", 8, FormatValue(coreConnCreateCmd.UserFields.DestinationSpecificParameterList[i].Length, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Value[" + i + "]", "Value of the Destination-specific Parameter.", coreConnCreateCmd.UserFields.DestinationSpecificParameterList[i].ValueList.Count * 8, FormatValue(coreConnCreateCmd.UserFields.DestinationSpecificParameterList[i].ValueList, coreConnCreateCmd.UserFields.DestinationSpecificParameterList[i].ValueList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CoreConnCreateCmd coreConnCreateCmd = (CoreConnCreateCmd)packet;
		int num = -1;
		if (index == ++num)
		{
			coreConnCreateCmd.UserFields.DestinationType = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			coreConnCreateCmd.UserFields.NumberOfDestinationSpecificParameters = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < coreConnCreateCmd.UserFields.DestinationSpecificParameterList.Count; i++)
		{
			if (index == ++num)
			{
				coreConnCreateCmd.UserFields.DestinationSpecificParameterList[i].Type = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				coreConnCreateCmd.UserFields.DestinationSpecificParameterList[i].Length = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				value = AddLeadingZerosAndCheckValueStringLength(value, coreConnCreateCmd.UserFields.DestinationSpecificParameterList[i].ValueList.Count);
				int num2 = 0;
				while (value.Length > 0)
				{
					string value2 = value.Substring(0, 2);
					value = value.Remove(0, 2);
					coreConnCreateCmd.UserFields.DestinationSpecificParameterList[i].ValueList[num2] = Convert.ToUInt32(value2, 16);
					num2++;
				}
			}
		}
	}
}
