using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CommandCompleteForReadDdbKeyEntryByIndexInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Read Ddb Key Entry By Index";

	public override string DisplayGroup => "Vendor Specific";

	public CommandCompleteForReadDdbKeyEntryByIndexInfo(CommandCompleteForReadDdbKeyEntryByIndex packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForReadDdbKeyEntryByIndex commandCompleteForReadDdbKeyEntryByIndex = (CommandCompleteForReadDdbKeyEntryByIndex)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num_HCI_Command_Packets", "The Number of HCI command packets which are allowed to be sent to the Controller from the Host", 8, FormatValue(commandCompleteForReadDdbKeyEntryByIndex.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForReadDdbKeyEntryByIndex.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForReadDdbKeyEntryByIndex.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(commandCompleteForReadDdbKeyEntryByIndex.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(commandCompleteForReadDdbKeyEntryByIndex.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Link_Key", "Link key of remote device", commandCompleteForReadDdbKeyEntryByIndex.UserFields.LinkKeyList.Count * 8, FormatValue(commandCompleteForReadDdbKeyEntryByIndex.UserFields.LinkKeyList, commandCompleteForReadDdbKeyEntryByIndex.UserFields.LinkKeyList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Key_Type", "Link key type of remote device", 8, FormatValue(commandCompleteForReadDdbKeyEntryByIndex.UserFields.KeyType, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("COD", "Class of Device", 32, FormatValue(commandCompleteForReadDdbKeyEntryByIndex.UserFields.Cod, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Max_Entries", "The ddb max entries", 16, FormatValue(commandCompleteForReadDdbKeyEntryByIndex.UserFields.MaxEntries, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

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