using System;
using QCRPG.Framework;

namespace QCRPG.TSL.FMHCI.Packets;

public class CommandCompleteForPinConnectivityTestInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Pin Connectivity Test";

	public override string DisplayGroup => "Diagnostic";

	public CommandCompleteForPinConnectivityTestInfo(CommandCompleteForPinConnectivityTest packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForPinConnectivityTest commandCompleteForPinConnectivityTest = (CommandCompleteForPinConnectivityTest)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num HCI Command Packets", "", 8, FormatValue(commandCompleteForPinConnectivityTest.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForPinConnectivityTest.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForPinConnectivityTest.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(commandCompleteForPinConnectivityTest.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(commandCompleteForPinConnectivityTest.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Number Of Tests Done", "The number of tests performed", 8, FormatValue(commandCompleteForPinConnectivityTest.UserFields.NumberOfTestsDone, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < commandCompleteForPinConnectivityTest.UserFields.TestResultsList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Test Module ID[" + i + "]", CommandCompleteForPinConnectivityTest.TestResultsSubField.TestModuleIdInfo.TestModuleIdToDescription(), 8, FormatValue(commandCompleteForPinConnectivityTest.UserFields.TestResultsList[i].TestModuleId, 8), CommandCompleteForPinConnectivityTest.TestResultsSubField.TestModuleIdInfo.TestModuleIdToString(CommandCompleteForPinConnectivityTest.TestResultsSubField.TestModuleIdInfo.ValueToTestModuleId(commandCompleteForPinConnectivityTest.UserFields.TestResultsList[i].TestModuleId)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Test Result[" + i + "]", "", 16, FormatValue(commandCompleteForPinConnectivityTest.UserFields.TestResultsList[i].TestResult, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CommandCompleteForPinConnectivityTest commandCompleteForPinConnectivityTest = (CommandCompleteForPinConnectivityTest)packet;
		int num = -1;
		if (index == ++num)
		{
			commandCompleteForPinConnectivityTest.UserFields.NumHciCommandPackets = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForPinConnectivityTest.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			commandCompleteForPinConnectivityTest.UserFields.NumberOfTestsDone = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < commandCompleteForPinConnectivityTest.UserFields.TestResultsList.Count; i++)
		{
			if (index == ++num)
			{
				commandCompleteForPinConnectivityTest.UserFields.TestResultsList[i].TestModuleId = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				commandCompleteForPinConnectivityTest.UserFields.TestResultsList[i].TestResult = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
