using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeExtendedAdvertisingReportInfo : PacketInfoBase
{
	public override string Name => "Le Extended Advertising Report";

	public override string DisplayGroup => "LE Controller";

	public LeExtendedAdvertisingReportInfo(LeExtendedAdvertisingReport packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeExtendedAdvertisingReport leExtendedAdvertisingReport = (LeExtendedAdvertisingReport)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE Extended Advertising Report event", 8, FormatValue(leExtendedAdvertisingReport.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Num_Reports", LeExtendedAdvertisingReport.UserFieldsWrapper.NumReportsInfo.NumReportsToDescription(), 8, FormatValue(leExtendedAdvertisingReport.UserFields.NumReports, 8), LeExtendedAdvertisingReport.UserFieldsWrapper.NumReportsInfo.NumReportsToString(LeExtendedAdvertisingReport.UserFieldsWrapper.NumReportsInfo.ValueToNumReports(leExtendedAdvertisingReport.UserFields.NumReports)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < leExtendedAdvertisingReport.UserFields.ReportsList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Event_Type[" + i + "]", LeExtendedAdvertisingReport.ReportsSubField.EventTypeInfo.EventTypeToDescription(), 16, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].EventType, 16), LeExtendedAdvertisingReport.ReportsSubField.EventTypeInfo.EventTypeToString(LeExtendedAdvertisingReport.ReportsSubField.EventTypeInfo.ValueToEventType(leExtendedAdvertisingReport.UserFields.ReportsList[i].EventType)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Address_Type[" + i + "]", AdvertisingReportAddressTypeInfo.AdvertisingReportAddressTypeToDescription(), 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].AddressType, 8), AdvertisingReportAddressTypeInfo.AdvertisingReportAddressTypeToString(AdvertisingReportAddressTypeInfo.ValueToAdvertisingReportAddressType(leExtendedAdvertisingReport.UserFields.ReportsList[i].AddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Address[" + i + "]", "Public Device Address, Random Device Address, Public Identity Address or Random (static) Identity Address of the advertising device.", 48, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].Address, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			if (leExtendedAdvertisingReport.UserFields.ReportsList[i].PrimaryPhy >= 0 && leExtendedAdvertisingReport.UserFields.ReportsList[i].PrimaryPhy <= 1)
			{
				fieldInfoList.Add(new PacketFieldInfo("Primary_PHY[" + i + "]", AdvertisingPhyInfo.AdvertisingPhyToDescription(), 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].PrimaryPhy, 8), AdvertisingPhyInfo.AdvertisingPhyToString(AdvertisingPhyInfo.ValueToAdvertisingPhy(leExtendedAdvertisingReport.UserFields.ReportsList[i].PrimaryPhy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			}
			else if (leExtendedAdvertisingReport.UserFields.ReportsList[i].PrimaryPhy == 2)
			{
				fieldInfoList.Add(new PacketFieldInfo("Primary_PHY[" + i + "]", LeExtendedAdvertisingReport.ReportsSubField.PrimaryPhyInfo.PrimaryPhyToDescription(), 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].PrimaryPhy, 8), LeExtendedAdvertisingReport.ReportsSubField.PrimaryPhyInfo.PrimaryPhyToString(LeExtendedAdvertisingReport.ReportsSubField.PrimaryPhyInfo.ValueToPrimaryPhy(leExtendedAdvertisingReport.UserFields.ReportsList[i].PrimaryPhy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			}
			else if (leExtendedAdvertisingReport.UserFields.ReportsList[i].PrimaryPhy >= 3 && leExtendedAdvertisingReport.UserFields.ReportsList[i].PrimaryPhy <= 255)
			{
				fieldInfoList.Add(new PacketFieldInfo("Primary_PHY[" + i + "]", AdvertisingPhyInfo.AdvertisingPhyToDescription(), 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].PrimaryPhy, 8), AdvertisingPhyInfo.AdvertisingPhyToString(AdvertisingPhyInfo.ValueToAdvertisingPhy(leExtendedAdvertisingReport.UserFields.ReportsList[i].PrimaryPhy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			}
			else
			{
				fieldInfoList.Add(new PacketFieldInfo("Primary_PHY[" + i + "]", "", 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].PrimaryPhy, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			}
			if (leExtendedAdvertisingReport.UserFields.ReportsList[i].SecondaryPhy == 0)
			{
				fieldInfoList.Add(new PacketFieldInfo("Secondary_PHY[" + i + "]", LeExtendedAdvertisingReport.ReportsSubField.SecondaryPhyInfo.SecondaryPhyToDescription(), 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].SecondaryPhy, 8), LeExtendedAdvertisingReport.ReportsSubField.SecondaryPhyInfo.SecondaryPhyToString(LeExtendedAdvertisingReport.ReportsSubField.SecondaryPhyInfo.ValueToSecondaryPhy(leExtendedAdvertisingReport.UserFields.ReportsList[i].SecondaryPhy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			}
			else if (leExtendedAdvertisingReport.UserFields.ReportsList[i].SecondaryPhy >= 1 && leExtendedAdvertisingReport.UserFields.ReportsList[i].SecondaryPhy <= 255)
			{
				fieldInfoList.Add(new PacketFieldInfo("Secondary_PHY[" + i + "]", AdvertisingPhyInfo.AdvertisingPhyToDescription(), 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].SecondaryPhy, 8), AdvertisingPhyInfo.AdvertisingPhyToString(AdvertisingPhyInfo.ValueToAdvertisingPhy(leExtendedAdvertisingReport.UserFields.ReportsList[i].SecondaryPhy)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			}
			else
			{
				fieldInfoList.Add(new PacketFieldInfo("Secondary_PHY[" + i + "]", "", 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].SecondaryPhy, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			}
			fieldInfoList.Add(new PacketFieldInfo("Advertising_SID[" + i + "]", "", 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].AdvertisingSid, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Tx_Power[" + i + "]", "Size: 1 Octet (signed integer). Range: -127 ≤ N ≤ +126, Units: dBm. Tx Power information not available (127).\r\n\r\n" + AdvertisingReportTxPowerInfo.AdvertisingReportTxPowerToDescription(), 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].TxPower, 8), AdvertisingReportTxPowerInfo.AdvertisingReportTxPowerToString(AdvertisingReportTxPowerInfo.ValueToAdvertisingReportTxPower(leExtendedAdvertisingReport.UserFields.ReportsList[i].TxPower)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("RSSI[" + i + "]", "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(leExtendedAdvertisingReport.UserFields.ReportsList[i].Rssi, 8), AdvertisingRssiInfo.AdvertisingRssiToString(AdvertisingRssiInfo.ValueToAdvertisingRssi(leExtendedAdvertisingReport.UserFields.ReportsList[i].Rssi)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Periodic_Advertising_Interval[" + i + "]", LeExtendedAdvertisingReport.ReportsSubField.PeriodicAdvertisingIntervalInfo.PeriodicAdvertisingIntervalToDescription(), 16, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].PeriodicAdvertisingInterval, 16), ValueTimes1p25MsecExpression.ValueTimes1p25MsecToString(leExtendedAdvertisingReport.UserFields.ReportsList[i].PeriodicAdvertisingInterval), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			if (leExtendedAdvertisingReport.UserFields.ReportsList[i].DirectAddressType >= 0 && leExtendedAdvertisingReport.UserFields.ReportsList[i].DirectAddressType <= 254)
			{
				fieldInfoList.Add(new PacketFieldInfo("Direct_Address_Type[" + i + "]", PeerResolvableAddressTypeInfo.PeerResolvableAddressTypeToDescription(), 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].DirectAddressType, 8), PeerResolvableAddressTypeInfo.PeerResolvableAddressTypeToString(PeerResolvableAddressTypeInfo.ValueToPeerResolvableAddressType(leExtendedAdvertisingReport.UserFields.ReportsList[i].DirectAddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			}
			else if (leExtendedAdvertisingReport.UserFields.ReportsList[i].DirectAddressType == 255)
			{
				fieldInfoList.Add(new PacketFieldInfo("Direct_Address_Type[" + i + "]", LeExtendedAdvertisingReport.ReportsSubField.DirectAddressTypeInfo.DirectAddressTypeToDescription(), 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].DirectAddressType, 8), LeExtendedAdvertisingReport.ReportsSubField.DirectAddressTypeInfo.DirectAddressTypeToString(LeExtendedAdvertisingReport.ReportsSubField.DirectAddressTypeInfo.ValueToDirectAddressType(leExtendedAdvertisingReport.UserFields.ReportsList[i].DirectAddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			}
			else
			{
				fieldInfoList.Add(new PacketFieldInfo("Direct_Address_Type[" + i + "]", "", 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].DirectAddressType, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			}
			fieldInfoList.Add(new PacketFieldInfo("Direct_Address[" + i + "]", "Public Device Address, Random Device Address, Public Identity Address or Random (static) Identity Address of the target device", 48, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].DirectAddress, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Data_Length[" + i + "]", "Length of the Data[i] field for each device which responded", 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].DataLength, 8), "", "00", "E5", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Data[" + i + "]", "Data_Length[i] octets of advertising or scan response data formatted as defined in [Vol 3] Part C, Section 11. Note: Each element of this array has a variable length.", leExtendedAdvertisingReport.UserFields.ReportsList[i].DataList.Count * 8, FormatValue(leExtendedAdvertisingReport.UserFields.ReportsList[i].DataList, leExtendedAdvertisingReport.UserFields.ReportsList[i].DataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeExtendedAdvertisingReport leExtendedAdvertisingReport = (LeExtendedAdvertisingReport)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leExtendedAdvertisingReport.UserFields.NumReports = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < leExtendedAdvertisingReport.UserFields.ReportsList.Count; i++)
		{
			if (index == ++num)
			{
				leExtendedAdvertisingReport.UserFields.ReportsList[i].EventType = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leExtendedAdvertisingReport.UserFields.ReportsList[i].AddressType = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leExtendedAdvertisingReport.UserFields.ReportsList[i].Address = Convert.ToUInt64(value, 16);
				break;
			}
			if (index == ++num)
			{
				leExtendedAdvertisingReport.UserFields.ReportsList[i].PrimaryPhy = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leExtendedAdvertisingReport.UserFields.ReportsList[i].SecondaryPhy = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leExtendedAdvertisingReport.UserFields.ReportsList[i].AdvertisingSid = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leExtendedAdvertisingReport.UserFields.ReportsList[i].TxPower = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leExtendedAdvertisingReport.UserFields.ReportsList[i].Rssi = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leExtendedAdvertisingReport.UserFields.ReportsList[i].PeriodicAdvertisingInterval = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leExtendedAdvertisingReport.UserFields.ReportsList[i].DirectAddressType = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leExtendedAdvertisingReport.UserFields.ReportsList[i].DirectAddress = Convert.ToUInt64(value, 16);
				break;
			}
			if (index == ++num)
			{
				leExtendedAdvertisingReport.UserFields.ReportsList[i].DataLength = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				value = AddLeadingZerosAndCheckValueStringLength(value, leExtendedAdvertisingReport.UserFields.ReportsList[i].DataList.Count);
				int num2 = 0;
				while (value.Length > 0)
				{
					string value2 = value.Substring(0, 2);
					value = value.Remove(0, 2);
					leExtendedAdvertisingReport.UserFields.ReportsList[i].DataList[num2] = Convert.ToUInt32(value2, 16);
					num2++;
				}
			}
		}
	}
}
