using System;
using QCRPG.Framework;

namespace QCRPG.TSL.NFC.Packets;

public class CoreInitRspInfo : PacketInfoBase
{
	public override string Name => "Core Init Rsp";

	public override string DisplayGroup => "NCI Core";

	public CoreInitRspInfo(CoreInitRsp packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CoreInitRsp coreInitRsp = (CoreInitRsp)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Status", StatusCodesInfo.StatusCodesToDescription(), 8, FormatValue(coreInitRsp.UserFields.Status, 8), StatusCodesInfo.StatusCodesToString(StatusCodesInfo.ValueToStatusCodes(coreInitRsp.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("NFCC Features", CoreInitRsp.UserFieldsWrapper.NfccFeaturesInfo.NfccFeaturesToDescription(), 32, FormatValue(coreInitRsp.UserFields.NfccFeatures, 32), CoreInitRsp.UserFieldsWrapper.NfccFeaturesInfo.NfccFeaturesToString(CoreInitRsp.UserFieldsWrapper.NfccFeaturesInfo.ValueToNfccFeatures(coreInitRsp.UserFields.NfccFeatures)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number Of Supported RF Interfaces", "Number of Supported RF Interface fields to follow (n).", 8, FormatValue(coreInitRsp.UserFields.NumberOfSupportedRfInterfaces, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < coreInitRsp.UserFields.SupportedRfInterfaceList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Supported RF Interface[" + i + "]", RfInterfacesInfo.RfInterfacesToDescription(), 8, FormatValue(coreInitRsp.UserFields.SupportedRfInterfaceList[i], 8), RfInterfacesInfo.RfInterfacesToString(RfInterfacesInfo.ValueToRfInterfaces(coreInitRsp.UserFields.SupportedRfInterfaceList[i])), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
		fieldInfoList.Add(new PacketFieldInfo("Max Logical Connections", CoreInitRsp.UserFieldsWrapper.MaxLogicalConnectionsInfo.MaxLogicalConnectionsToDescription(), 8, FormatValue(coreInitRsp.UserFields.MaxLogicalConnections, 8), CoreInitRsp.UserFieldsWrapper.MaxLogicalConnectionsInfo.MaxLogicalConnectionsToString(CoreInitRsp.UserFieldsWrapper.MaxLogicalConnectionsInfo.ValueToMaxLogicalConnections(coreInitRsp.UserFields.MaxLogicalConnections)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max Routing Table Size", "Indicates the maximum amount of data in Octets that are possible in a routing configuration (see Section 6.3). If Listen Mode Routing is not supported, then the value SHALL be 0x0000.", 16, FormatValue(coreInitRsp.UserFields.MaxRoutingTableSize, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max Control Packet Payload Size", "Indicates the maximum payload length of a NCI Control Packet that the NFCC is able to receive. Valid range is 32 to 255.", 8, FormatValue(coreInitRsp.UserFields.MaxControlPacketPayloadSize, 8), "", "20", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max Size For Large Parameters", "The maximum size in octets for the sum of the sizes of PB_H_INFO and LB_H_INFO_RESP parameter values.", 16, FormatValue(coreInitRsp.UserFields.MaxSizeForLargeParameters, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Manufacturer ID", "IC Manufacturer ID, as defined in [MANU]. If this information is not available, the NFCC SHALL return 0x00.", 8, FormatValue(coreInitRsp.UserFields.ManufacturerId, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Manufacturer Specific Information", "This field contains NFCC manufacturer specific information like chip version, firmware version, etc., encoded in a manufacturer-specific mode. If this information is not available or if the Manufacturer ID is set to 0x00, the NFCC SHALL return all octets containing 0x00.", 32, FormatValue(coreInitRsp.UserFields.ManufacturerSpecificInformation, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CoreInitRsp coreInitRsp = (CoreInitRsp)packet;
		int num = -1;
		if (index == ++num)
		{
			coreInitRsp.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			coreInitRsp.UserFields.NfccFeatures = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			coreInitRsp.UserFields.NumberOfSupportedRfInterfaces = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < coreInitRsp.UserFields.SupportedRfInterfaceList.Count; i++)
		{
			if (index == ++num)
			{
				coreInitRsp.UserFields.SupportedRfInterfaceList[i] = Convert.ToUInt32(value, 16);
				return;
			}
		}
		if (index == ++num)
		{
			coreInitRsp.UserFields.MaxLogicalConnections = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			coreInitRsp.UserFields.MaxRoutingTableSize = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			coreInitRsp.UserFields.MaxControlPacketPayloadSize = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			coreInitRsp.UserFields.MaxSizeForLargeParameters = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			coreInitRsp.UserFields.ManufacturerId = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			coreInitRsp.UserFields.ManufacturerSpecificInformation = Convert.ToUInt32(value, 16);
		}
	}
}
