using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CommandCompleteForHogpReadDeviceInfoInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Hogp Read Device Info";

	public override string DisplayGroup => "Vendor Specific";

	public CommandCompleteForHogpReadDeviceInfoInfo(CommandCompleteForHogpReadDeviceInfo packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForHogpReadDeviceInfo commandCompleteForHogpReadDeviceInfo = (CommandCompleteForHogpReadDeviceInfo)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num HCI Command Packets", "", 8, FormatValue(commandCompleteForHogpReadDeviceInfo.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForHogpReadDeviceInfo.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForHogpReadDeviceInfo.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(commandCompleteForHogpReadDeviceInfo.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(commandCompleteForHogpReadDeviceInfo.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sub OpCode", "HCI_VSC_HOGP_READ_DEVICE_INFO", 8, FormatValue(commandCompleteForHogpReadDeviceInfo.UserFields.SubOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Address", "", 48, FormatValue(commandCompleteForHogpReadDeviceInfo.UserFields.Address, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("AddrType", "", 8, FormatValue(commandCompleteForHogpReadDeviceInfo.UserFields.Addrtype, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("LTK", "", commandCompleteForHogpReadDeviceInfo.UserFields.LtkList.Count * 8, FormatValue(commandCompleteForHogpReadDeviceInfo.UserFields.LtkList, commandCompleteForHogpReadDeviceInfo.UserFields.LtkList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Rand", "", 64, FormatValue(commandCompleteForHogpReadDeviceInfo.UserFields.Rand, 64), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("IRK", "", commandCompleteForHogpReadDeviceInfo.UserFields.IrkList.Count * 8, FormatValue(commandCompleteForHogpReadDeviceInfo.UserFields.IrkList, commandCompleteForHogpReadDeviceInfo.UserFields.IrkList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Ediv", "", 16, FormatValue(commandCompleteForHogpReadDeviceInfo.UserFields.Ediv, 16), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CommandCompleteForHogpReadDeviceInfo commandCompleteForHogpReadDeviceInfo = (CommandCompleteForHogpReadDeviceInfo)packet;
		int num = -1;
		if (index == ++num)
		{
			commandCompleteForHogpReadDeviceInfo.UserFields.NumHciCommandPackets = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForHogpReadDeviceInfo.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForHogpReadDeviceInfo.UserFields.Address = Convert.ToUInt64(value, 16);
			return;
		}
		if (index == ++num)
		{
			commandCompleteForHogpReadDeviceInfo.UserFields.Addrtype = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, commandCompleteForHogpReadDeviceInfo.UserFields.LtkList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				commandCompleteForHogpReadDeviceInfo.UserFields.LtkList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			commandCompleteForHogpReadDeviceInfo.UserFields.Rand = Convert.ToUInt64(value, 16);
			return;
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, commandCompleteForHogpReadDeviceInfo.UserFields.IrkList.Count);
			int num3 = 0;
			while (value.Length > 0)
			{
				string value3 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				commandCompleteForHogpReadDeviceInfo.UserFields.IrkList[num3] = Convert.ToUInt32(value3, 16);
				num3++;
			}
		}
		if (index == ++num)
		{
			commandCompleteForHogpReadDeviceInfo.UserFields.Ediv = Convert.ToUInt32(value, 16);
		}
	}
}
