using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeDirectedAdvertisingReportInfo : PacketInfoBase
{
	public override string Name => "Le Directed Advertising Report";

	public override string DisplayGroup => "LE Controller";

	public LeDirectedAdvertisingReportInfo(LeDirectedAdvertisingReport packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		LeDirectedAdvertisingReport leDirectedAdvertisingReport = (LeDirectedAdvertisingReport)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Subevent_Code", "Subevent code for LE Directed Advertising Report Event", 8, FormatValue(leDirectedAdvertisingReport.UserFields.SubeventCode, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Num_Reports", NumberOfReportsInfo.NumberOfReportsToDescription(), 8, FormatValue(leDirectedAdvertisingReport.UserFields.NumReports, 8), NumberOfReportsInfo.NumberOfReportsToString(NumberOfReportsInfo.ValueToNumberOfReports(leDirectedAdvertisingReport.UserFields.NumReports)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		for (int i = 0; i < leDirectedAdvertisingReport.UserFields.ReportsList.Count; i++)
		{
			fieldInfoList.Add(new PacketFieldInfo("Event_Type[" + i + "]", LeDirectedAdvertisingReport.ReportsSubField.EventTypeInfo.EventTypeToDescription(), 8, FormatValue(leDirectedAdvertisingReport.UserFields.ReportsList[i].EventType, 8), LeDirectedAdvertisingReport.ReportsSubField.EventTypeInfo.EventTypeToString(LeDirectedAdvertisingReport.ReportsSubField.EventTypeInfo.ValueToEventType(leDirectedAdvertisingReport.UserFields.ReportsList[i].EventType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Address_Type[" + i + "]", AdvertisingReportAddressTypeInfo.AdvertisingReportAddressTypeToDescription(), 8, FormatValue(leDirectedAdvertisingReport.UserFields.ReportsList[i].AddressType, 8), AdvertisingReportAddressTypeInfo.AdvertisingReportAddressTypeToString(AdvertisingReportAddressTypeInfo.ValueToAdvertisingReportAddressType(leDirectedAdvertisingReport.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(leDirectedAdvertisingReport.UserFields.ReportsList[i].Address, 48), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Direct_Address_Type[" + i + "]", LeDirectedAdvertisingReport.ReportsSubField.DirectAddressTypeInfo.DirectAddressTypeToDescription(), 8, FormatValue(leDirectedAdvertisingReport.UserFields.ReportsList[i].DirectAddressType, 8), LeDirectedAdvertisingReport.ReportsSubField.DirectAddressTypeInfo.DirectAddressTypeToString(LeDirectedAdvertisingReport.ReportsSubField.DirectAddressTypeInfo.ValueToDirectAddressType(leDirectedAdvertisingReport.UserFields.ReportsList[i].DirectAddressType)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
			fieldInfoList.Add(new PacketFieldInfo("Direct_Address[" + i + "]", "Random Device Address", 48, FormatValue(leDirectedAdvertisingReport.UserFields.ReportsList[i].DirectAddress, 48), "", "", "", settable: true, littleEndianTransport: true, 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 (21 to 126)\r\n\r\n" + AdvertisingRssiInfo.AdvertisingRssiToDescription(), 8, FormatValue(leDirectedAdvertisingReport.UserFields.ReportsList[i].Rssi, 8), AdvertisingRssiInfo.AdvertisingRssiToString(AdvertisingRssiInfo.ValueToAdvertisingRssi(leDirectedAdvertisingReport.UserFields.ReportsList[i].Rssi)), "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		}
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		LeDirectedAdvertisingReport leDirectedAdvertisingReport = (LeDirectedAdvertisingReport)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field SubeventCode");
		}
		if (index == ++num)
		{
			leDirectedAdvertisingReport.UserFields.NumReports = Convert.ToUInt32(value, 16);
			return;
		}
		for (int i = 0; i < leDirectedAdvertisingReport.UserFields.ReportsList.Count; i++)
		{
			if (index == ++num)
			{
				leDirectedAdvertisingReport.UserFields.ReportsList[i].EventType = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leDirectedAdvertisingReport.UserFields.ReportsList[i].AddressType = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leDirectedAdvertisingReport.UserFields.ReportsList[i].Address = Convert.ToUInt64(value, 16);
				break;
			}
			if (index == ++num)
			{
				leDirectedAdvertisingReport.UserFields.ReportsList[i].DirectAddressType = Convert.ToUInt32(value, 16);
				break;
			}
			if (index == ++num)
			{
				leDirectedAdvertisingReport.UserFields.ReportsList[i].DirectAddress = Convert.ToUInt64(value, 16);
				break;
			}
			if (index == ++num)
			{
				leDirectedAdvertisingReport.UserFields.ReportsList[i].Rssi = Convert.ToUInt32(value, 16);
				break;
			}
		}
	}
}
