using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CommandCompleteForReadLocalOobExtendedDataInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Read Local Oob Extended Data";

	public override string DisplayGroup => "Host Control and Baseband";

	public CommandCompleteForReadLocalOobExtendedDataInfo(CommandCompleteForReadLocalOobExtendedData packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForReadLocalOobExtendedData commandCompleteForReadLocalOobExtendedData = (CommandCompleteForReadLocalOobExtendedData)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num HCI Command Packets", "", 8, FormatValue(commandCompleteForReadLocalOobExtendedData.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForReadLocalOobExtendedData.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForReadLocalOobExtendedData.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(commandCompleteForReadLocalOobExtendedData.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(commandCompleteForReadLocalOobExtendedData.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("C_192", "Simple Pairing Hash C derived from the P-192 public key", commandCompleteForReadLocalOobExtendedData.UserFields.C192List.Count * 8, FormatValue(commandCompleteForReadLocalOobExtendedData.UserFields.C192List, commandCompleteForReadLocalOobExtendedData.UserFields.C192List.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("R_192", "Simple Pairing Randomizer associated with the P-192 public key", commandCompleteForReadLocalOobExtendedData.UserFields.R192List.Count * 8, FormatValue(commandCompleteForReadLocalOobExtendedData.UserFields.R192List, commandCompleteForReadLocalOobExtendedData.UserFields.R192List.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("C_256", "Simple Pairing Hash C derived from the P-256 public key", commandCompleteForReadLocalOobExtendedData.UserFields.C256List.Count * 8, FormatValue(commandCompleteForReadLocalOobExtendedData.UserFields.C256List, commandCompleteForReadLocalOobExtendedData.UserFields.C256List.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("R_256", "Simple Pairing Randomizer associated with the P-256 public key", commandCompleteForReadLocalOobExtendedData.UserFields.R256List.Count * 8, FormatValue(commandCompleteForReadLocalOobExtendedData.UserFields.R256List, commandCompleteForReadLocalOobExtendedData.UserFields.R256List.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CommandCompleteForReadLocalOobExtendedData commandCompleteForReadLocalOobExtendedData = (CommandCompleteForReadLocalOobExtendedData)packet;
		int num = -1;
		if (index == ++num)
		{
			commandCompleteForReadLocalOobExtendedData.UserFields.NumHciCommandPackets = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForReadLocalOobExtendedData.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, commandCompleteForReadLocalOobExtendedData.UserFields.C192List.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				commandCompleteForReadLocalOobExtendedData.UserFields.C192List[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, commandCompleteForReadLocalOobExtendedData.UserFields.R192List.Count);
			int num3 = 0;
			while (value.Length > 0)
			{
				string value3 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				commandCompleteForReadLocalOobExtendedData.UserFields.R192List[num3] = Convert.ToUInt32(value3, 16);
				num3++;
			}
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, commandCompleteForReadLocalOobExtendedData.UserFields.C256List.Count);
			int num4 = 0;
			while (value.Length > 0)
			{
				string value4 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				commandCompleteForReadLocalOobExtendedData.UserFields.C256List[num4] = Convert.ToUInt32(value4, 16);
				num4++;
			}
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, commandCompleteForReadLocalOobExtendedData.UserFields.R256List.Count);
			int num5 = 0;
			while (value.Length > 0)
			{
				string value5 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				commandCompleteForReadLocalOobExtendedData.UserFields.R256List[num5] = Convert.ToUInt32(value5, 16);
				num5++;
			}
		}
	}
}
