using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeScanRequestReceivedInfo : PacketInfoBase
{
	public override string Name => "Le Scan Request Received";

	public override string DisplayGroup => "LE Controller";

	public LeScanRequestReceivedInfo(LeScanRequestReceived packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeScanRequestReceived leScanRequestReceived = (LeScanRequestReceived)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE Scan Request Received event", 8, FormatValue(leScanRequestReceived.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Handle", "Used to identify an advertising set", 8, FormatValue(leScanRequestReceived.UserFields.AdvertisingHandle, 8), "", "00", "EF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Scanner_Address_Type", PeerResolvableAddressTypeInfo.PeerResolvableAddressTypeToDescription(), 8, FormatValue(leScanRequestReceived.UserFields.ScannerAddressType, 8), PeerResolvableAddressTypeInfo.PeerResolvableAddressTypeToString(PeerResolvableAddressTypeInfo.ValueToPeerResolvableAddressType(leScanRequestReceived.UserFields.ScannerAddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Scanner_Address", "Public Device Address, Random Device Address, Public Identity Address, or Random (static) Identity Address of the advertising device.", 48, FormatValue(leScanRequestReceived.UserFields.ScannerAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeScanRequestReceived leScanRequestReceived = (LeScanRequestReceived)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leScanRequestReceived.UserFields.AdvertisingHandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leScanRequestReceived.UserFields.ScannerAddressType = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			leScanRequestReceived.UserFields.ScannerAddress = Convert.ToUInt64(value, 16);
		}
	}
}
