using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class CommandCompleteForLeBatchScanReadBatchScanResultsTruncatedInfo : PacketInfoBase
{
	public override string Name => "Command Complete For Le Batch Scan Read Batch Scan Results Truncated";

	public override string DisplayGroup => "Vendor Specific";

	public CommandCompleteForLeBatchScanReadBatchScanResultsTruncatedInfo(CommandCompleteForLeBatchScanReadBatchScanResultsTruncated packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		CommandCompleteForLeBatchScanReadBatchScanResultsTruncated commandCompleteForLeBatchScanReadBatchScanResultsTruncated = (CommandCompleteForLeBatchScanReadBatchScanResultsTruncated)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Num HCI Command Packets", "", 8, FormatValue(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.NumHciCommandPackets, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Command OpCode", CommandOpcodeInfo.CommandOpcodeToDescription(), 16, FormatValue(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.CommandOpcode, 16), CommandOpcodeInfo.CommandOpcodeToString(CommandOpcodeInfo.ValueToCommandOpcode(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.CommandOpcode)), "", "", settable: false, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Status", ErrorCodeInfo.ErrorCodeToDescription(), 8, FormatValue(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.Status, 8), ErrorCodeInfo.ErrorCodeToString(ErrorCodeInfo.ValueToErrorCode(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.Status)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Batch_Scan_opcode", "Read Batch Scan Results", 8, FormatValue(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.BatchScanOpcode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Batch_Scan_Data_read", "Truncated mode data", 8, FormatValue(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.BatchScanDataRead, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("num_of_records", "number of records of Batch_Scan_data_read", 8, FormatValue(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.NumOfRecords, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.FormatOfDataList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Address[" + i + "]", "", 48, FormatValue(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.FormatOfDataList[i].Address, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Address_Type[" + i + "]", DeviceAddressTypeInfo.DeviceAddressTypeToDescription(), 8, FormatValue(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.FormatOfDataList[i].AddressType, 8), DeviceAddressTypeInfo.DeviceAddressTypeToString(DeviceAddressTypeInfo.ValueToDeviceAddressType(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.FormatOfDataList[i].AddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Tx_Pwr[" + i + "]", "", 8, FormatValue(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.FormatOfDataList[i].TxPwr, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("RSSI[" + i + "]", "", 8, FormatValue(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.FormatOfDataList[i].Rssi, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Timestamp[" + i + "]", "The unit of timestamp is 50ms. The value of timestamp is based off when the Read_Batch_Scan_Results_Sub_cmd is given by host.", 16, FormatValue(commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.FormatOfDataList[i].Timestamp, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		CommandCompleteForLeBatchScanReadBatchScanResultsTruncated commandCompleteForLeBatchScanReadBatchScanResultsTruncated = (CommandCompleteForLeBatchScanReadBatchScanResultsTruncated)packet;
		int num = -1;
		if (index == ++num)
		{
			commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.NumHciCommandPackets = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field CommandOpcode");
		}
		if (index == ++num)
		{
			commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.Status = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field BatchScanOpcode");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field BatchScanDataRead");
		}
		if (index == ++num)
		{
			commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.NumOfRecords = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.FormatOfDataList.Count; i++)
		{
			if (index == ++num)
			{
				commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.FormatOfDataList[i].Address = Convert.ToUInt64(value, 16);
				break;
			}
			if (index == ++num)
			{
				commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.FormatOfDataList[i].AddressType = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.FormatOfDataList[i].TxPwr = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.FormatOfDataList[i].Rssi = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				commandCompleteForLeBatchScanReadBatchScanResultsTruncated.UserFields.FormatOfDataList[i].Timestamp = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
