using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeAoaReportInfo : PacketInfoBase
{
	public override string Name => "Le Aoa Report";

	public override string DisplayGroup => "LE Controller";

	public LeAoaReportInfo(LeAoaReport packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeAoaReport leAoaReport = (LeAoaReport)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE_AoA_Report event", 8, FormatValue(leAoaReport.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Connection_Handle", "Connection_Handle to be used to identify a connection. Range 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(leAoaReport.UserFields.ConnectionHandle, 16), "", "0EFF", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RX_PHY", LeAoaReport.UserFieldsWrapper.RxPhyInfo.RxPhyToDescription(), 8, FormatValue(leAoaReport.UserFields.RxPhy, 8), LeAoaReport.UserFieldsWrapper.RxPhyInfo.RxPhyToString(LeAoaReport.UserFieldsWrapper.RxPhyInfo.ValueToRxPhy(leAoaReport.UserFields.RxPhy)), "", "", settable: true, littleEndianTransport: false, 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(leAoaReport.UserFields.Rssi, 8), AdvertisingRssiInfo.AdvertisingRssiToString(AdvertisingRssiInfo.ValueToAdvertisingRssi(leAoaReport.UserFields.Rssi)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Supplemental_Type", LeAoaReport.UserFieldsWrapper.SupplementalTypeInfo.SupplementalTypeToDescription(), 8, FormatValue(leAoaReport.UserFields.SupplementalType, 8), LeAoaReport.UserFieldsWrapper.SupplementalTypeInfo.SupplementalTypeToString(LeAoaReport.UserFieldsWrapper.SupplementalTypeInfo.ValueToSupplementalType(leAoaReport.UserFields.SupplementalType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Data_Channel_Index", "The index of the data channel on which the data channel PDU was received.", 8, FormatValue(leAoaReport.UserFields.DataChannelIndex, 8), "", "24", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sample_Count", "Total number of I_samples and Q_samples (the same number shall apply to both). The number is dependent on the used switch and sample slot durations.", 8, FormatValue(leAoaReport.UserFields.SampleCount, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < leAoaReport.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(leAoaReport.UserFields.SamplesList[i].ISample, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Q_Sample[" + i + "]", "", 8, FormatValue(leAoaReport.UserFields.SamplesList[i].QSample, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

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