using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CommandCompleteForNvmAccessGetInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Nvm Access Get";

	public override string DisplayGroup => "Vendor Specific";

	public CommandCompleteForNvmAccessGetInfo(CommandCompleteForNvmAccessGet packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForNvmAccessGet commandCompleteForNvmAccessGet = (CommandCompleteForNvmAccessGet)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num HCI Command Packets", "", 8, FormatValue(commandCompleteForNvmAccessGet.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForNvmAccessGet.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForNvmAccessGet.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(commandCompleteForNvmAccessGet.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(commandCompleteForNvmAccessGet.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sub-Opcode", "NVM_ACCESS_GET", 8, FormatValue(commandCompleteForNvmAccessGet.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tag Number", "", 8, FormatValue(commandCompleteForNvmAccessGet.UserFields.TagNumber, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tag Length", "", 8, FormatValue(commandCompleteForNvmAccessGet.UserFields.TagLength, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Tag Value", "", commandCompleteForNvmAccessGet.UserFields.TagValueList.Count * 8, FormatValue(commandCompleteForNvmAccessGet.UserFields.TagValueList, commandCompleteForNvmAccessGet.UserFields.TagValueList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CommandCompleteForNvmAccessGet commandCompleteForNvmAccessGet = (CommandCompleteForNvmAccessGet)packet;
		int num = -1;
		if (index == ++num)
		{
			commandCompleteForNvmAccessGet.UserFields.NumHciCommandPackets = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForNvmAccessGet.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForNvmAccessGet.UserFields.TagNumber = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			commandCompleteForNvmAccessGet.UserFields.TagLength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, commandCompleteForNvmAccessGet.UserFields.TagValueList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				commandCompleteForNvmAccessGet.UserFields.TagValueList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
