using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeConnectionlessIQReportInfo : PacketInfoBase
{
	public override string Name => "Le Connectionless I Q Report";

	public override string DisplayGroup => "LE Controller";

	public LeConnectionlessIQReportInfo(LeConnectionlessIQReport packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeConnectionlessIQReport leConnectionlessIQReport = (LeConnectionlessIQReport)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE Connectionless I&Q Report event", 8, FormatValue(leConnectionlessIQReport.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Sync_Handle", "Sync_Handle to be used to identify the periodic advertiser, Range: 0x0000-0x0EFF (0x0F00 - 0x0FFF Reserved for future use)", 16, FormatValue(leConnectionlessIQReport.UserFields.SyncHandle, 16), "", "0000", "0EFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Channel_Index", "The index of the channel on which the AUX_SYNC_IND PDU was received. Range: 0x00-0x24 (Other values are reserved for future use)", 8, FormatValue(leConnectionlessIQReport.UserFields.ChannelIndex, 8), "", "00", "24", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RSSI", "", 16, FormatValue(leConnectionlessIQReport.UserFields.Rssi, 16), Rssi2bytesExpression.Rssi2bytesToString(leConnectionlessIQReport.UserFields.Rssi), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("RSSI_Antenna_ID", "", 8, FormatValue(leConnectionlessIQReport.UserFields.RssiAntennaId, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("CTE_Type", AodSupplementalTypeInfo.AodSupplementalTypeToDescription(), 8, FormatValue(leConnectionlessIQReport.UserFields.CteType, 8), AodSupplementalTypeInfo.AodSupplementalTypeToString(AodSupplementalTypeInfo.ValueToAodSupplementalType(leConnectionlessIQReport.UserFields.CteType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Slot_Durations", SlotDurationsInfo.SlotDurationsToDescription(), 8, FormatValue(leConnectionlessIQReport.UserFields.SlotDurations, 8), SlotDurationsInfo.SlotDurationsToString(SlotDurationsInfo.ValueToSlotDurations(leConnectionlessIQReport.UserFields.SlotDurations)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Packet_Status", "Indicates whether the received packet had a valid CRC\r\n\r\n" + LeConnectionlessIQReport.UserFieldsWrapper.PacketStatusInfo.PacketStatusToDescription(), 8, FormatValue(leConnectionlessIQReport.UserFields.PacketStatus, 8), LeConnectionlessIQReport.UserFieldsWrapper.PacketStatusInfo.PacketStatusToString(LeConnectionlessIQReport.UserFieldsWrapper.PacketStatusInfo.ValueToPacketStatus(leConnectionlessIQReport.UserFields.PacketStatus)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("paEventCounter", "", 16, FormatValue(leConnectionlessIQReport.UserFields.Paeventcounter, 16), "", "", "", settable: true, littleEndianTransport: true, 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(leConnectionlessIQReport.UserFields.SampleCount, 8), "", "09", "52", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < leConnectionlessIQReport.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(leConnectionlessIQReport.UserFields.SamplesList[i].ISample, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Q_Sample[" + i + "]", "", 8, FormatValue(leConnectionlessIQReport.UserFields.SamplesList[i].QSample, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeConnectionlessIQReport leConnectionlessIQReport = (LeConnectionlessIQReport)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leConnectionlessIQReport.UserFields.SyncHandle = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leConnectionlessIQReport.UserFields.ChannelIndex = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leConnectionlessIQReport.UserFields.Rssi = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leConnectionlessIQReport.UserFields.RssiAntennaId = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leConnectionlessIQReport.UserFields.CteType = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leConnectionlessIQReport.UserFields.SlotDurations = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leConnectionlessIQReport.UserFields.PacketStatus = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leConnectionlessIQReport.UserFields.Paeventcounter = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			leConnectionlessIQReport.UserFields.SampleCount = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < leConnectionlessIQReport.UserFields.SamplesList.Count; i++)
		{
			if (index == ++num)
			{
				leConnectionlessIQReport.UserFields.SamplesList[i].ISample = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leConnectionlessIQReport.UserFields.SamplesList[i].QSample = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
