using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeAdvertisingIandqReportInfo : PacketInfoBase
{
	public override string Name => "Le Advertising Iandq Report";

	public override string DisplayGroup => "LE Controller";

	public LeAdvertisingIandqReportInfo(LeAdvertisingIandqReport packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeAdvertisingIandqReport leAdvertisingIandqReport = (LeAdvertisingIandqReport)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE Advertising I&Q Report event", 8, FormatValue(leAdvertisingIandqReport.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Address_Type", PeerResolvableAddressTypeInfo.PeerResolvableAddressTypeToDescription(), 8, FormatValue(leAdvertisingIandqReport.UserFields.AddressType, 8), PeerResolvableAddressTypeInfo.PeerResolvableAddressTypeToString(PeerResolvableAddressTypeInfo.ValueToPeerResolvableAddressType(leAdvertisingIandqReport.UserFields.AddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Address", "Public Device Address, Random Device Address, Public Identity Address or Random (static) Identity Address of the device whose advertising PDU is being reported.", 16, FormatValue(leAdvertisingIandqReport.UserFields.Address, 16), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RSSI", "Size: 1 Octet (signed integer). Range: -127 ≤ N ≤ +20, Units: dBm. RSSI is not available (127). Reserved for future use (All other values)\r\n\r\n" + AdvertisingRssiInfo.AdvertisingRssiToDescription(), 8, FormatValue(leAdvertisingIandqReport.UserFields.Rssi, 8), AdvertisingRssiInfo.AdvertisingRssiToString(AdvertisingRssiInfo.ValueToAdvertisingRssi(leAdvertisingIandqReport.UserFields.Rssi)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Advertising_Channel_Index", "The index of the advertising channel on which the advertising PDU was received.\r\n\r\n" + LeAdvertisingIandqReport.UserFieldsWrapper.AdvertisingChannelIndexInfo.AdvertisingChannelIndexToDescription(), 8, FormatValue(leAdvertisingIandqReport.UserFields.AdvertisingChannelIndex, 8), LeAdvertisingIandqReport.UserFieldsWrapper.AdvertisingChannelIndexInfo.AdvertisingChannelIndexToString(LeAdvertisingIandqReport.UserFieldsWrapper.AdvertisingChannelIndexInfo.ValueToAdvertisingChannelIndex(leAdvertisingIandqReport.UserFields.AdvertisingChannelIndex)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Supplemental_Type", AodSupplementalTypeInfo.AodSupplementalTypeToDescription(), 8, FormatValue(leAdvertisingIandqReport.UserFields.SupplementalType, 8), AodSupplementalTypeInfo.AodSupplementalTypeToString(AodSupplementalTypeInfo.ValueToAodSupplementalType(leAdvertisingIandqReport.UserFields.SupplementalType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sample_Count", "Total number of used sampling opportunities included in this report. The number is dependent on the used switch and sample slot durations, see Section 7.8.XX+1 LE Set AoD Tx Parameters Command and [Vol. 6] Part B and Section 2.3.1.5.1.", 8, FormatValue(leAdvertisingIandqReport.UserFields.SampleCount, 8), "", "00", "A0", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < leAdvertisingIandqReport.UserFields.SamplesList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("I_Sample[" + i + "]", "The list of Q samples for the reported PDU. Each sample is in signed integer format. The list begins with the first sample for the PDU.", 8, FormatValue(leAdvertisingIandqReport.UserFields.SamplesList[i].ISample, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Q_Sample[" + i + "]", "", 8, FormatValue(leAdvertisingIandqReport.UserFields.SamplesList[i].QSample, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeAdvertisingIandqReport leAdvertisingIandqReport = (LeAdvertisingIandqReport)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leAdvertisingIandqReport.UserFields.AddressType = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leAdvertisingIandqReport.UserFields.Address = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leAdvertisingIandqReport.UserFields.Rssi = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leAdvertisingIandqReport.UserFields.AdvertisingChannelIndex = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leAdvertisingIandqReport.UserFields.SupplementalType = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leAdvertisingIandqReport.UserFields.SampleCount = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < leAdvertisingIandqReport.UserFields.SamplesList.Count; i++)
		{
			if (index == ++num)
			{
				leAdvertisingIandqReport.UserFields.SamplesList[i].ISample = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leAdvertisingIandqReport.UserFields.SamplesList[i].QSample = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
