using System;
using System.Collections.Generic;
using System.Text;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class LeExtendedAdvertisingReport : PacketBase
{
	public class UserFieldsWrapper
	{
		public enum NumReportsEnum
		{
			Reserved_for_future_use,
			Number_of_separate_reports_in_the_event,
			InvalidNumReportsValue
		}

		public static class NumReportsInfo
		{
			public static NumReportsEnum ValueToNumReports(uint value)
			{
				if (value == 0)
				{
					return NumReportsEnum.Reserved_for_future_use;
				}
				if (value >= 1 && value <= 10)
				{
					return NumReportsEnum.Number_of_separate_reports_in_the_event;
				}
				if (value >= 15 && value <= 255)
				{
					return NumReportsEnum.Reserved_for_future_use;
				}
				return NumReportsEnum.InvalidNumReportsValue;
			}

			public static uint NumReportsToValue(NumReportsEnum enumItem)
			{
				switch (enumItem)
				{
				case NumReportsEnum.Reserved_for_future_use:
					return 0u;
				case NumReportsEnum.Number_of_separate_reports_in_the_event:
					return 1u;
				default:
					if (enumItem == NumReportsEnum.Reserved_for_future_use)
					{
						return 15u;
					}
					return uint.MaxValue;
				}
			}

			public static string NumReportsToString(NumReportsEnum enumItem)
			{
				switch (enumItem)
				{
				case NumReportsEnum.Reserved_for_future_use:
					return "Reserved for future use";
				case NumReportsEnum.Number_of_separate_reports_in_the_event:
					return "Number of separate reports in the event";
				default:
					if (enumItem == NumReportsEnum.Reserved_for_future_use)
					{
						return "Reserved for future use";
					}
					return "Invalid NumReports Value";
				}
			}

			public static string NumReportsToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = Reserved for future use");
				stringBuilder.AppendLine("0x1-0xA = Number of separate reports in the event");
				stringBuilder.AppendLine("0xF-0xFF = Reserved for future use");
				return stringBuilder.ToString();
			}
		}

		private const uint _SubeventCode = 13u;

		private uint _NumReports;

		private List<ReportsSubField> _ReportsList = new List<ReportsSubField>();

		public uint SubeventCode => 13u;

		public uint NumReports
		{
			get
			{
				return _NumReports;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for NumReports is 0xFF");
				}
				_NumReports = value;
				while (_ReportsList.Count < _NumReports)
				{
					_ReportsList.Add(new ReportsSubField());
				}
				while (_ReportsList.Count > _NumReports)
				{
					_ReportsList.RemoveAt(_ReportsList.Count - 1);
				}
			}
		}

		public List<ReportsSubField> ReportsList => _ReportsList;

		public NumReportsEnum GetNumReportsAsNumReportsEnum()
		{
			return NumReportsInfo.ValueToNumReports(_NumReports);
		}

		public void SetNumReportsAsNumReportsEnum(NumReportsEnum enumItem)
		{
			NumReports = NumReportsInfo.NumReportsToValue(enumItem);
		}
	}

	public class ReportsSubField
	{
		public class EventTypeEnumCollection
		{
			private AssertBitEnum _ConnectableAdvertising;

			private AssertBitEnum _ScannableAdvertising;

			private AssertBitEnum _DirectedAdvertising;

			private AssertBitEnum _ScanResponse;

			private AssertBitEnum _LegacyAdvertisingPdusUsed;

			private AdvertisingDataStatusEnum _DataStatus;

			public AssertBitEnum ConnectableAdvertising
			{
				get
				{
					return _ConnectableAdvertising;
				}
				set
				{
					_ConnectableAdvertising = value;
				}
			}

			public AssertBitEnum ScannableAdvertising
			{
				get
				{
					return _ScannableAdvertising;
				}
				set
				{
					_ScannableAdvertising = value;
				}
			}

			public AssertBitEnum DirectedAdvertising
			{
				get
				{
					return _DirectedAdvertising;
				}
				set
				{
					_DirectedAdvertising = value;
				}
			}

			public AssertBitEnum ScanResponse
			{
				get
				{
					return _ScanResponse;
				}
				set
				{
					_ScanResponse = value;
				}
			}

			public AssertBitEnum LegacyAdvertisingPdusUsed
			{
				get
				{
					return _LegacyAdvertisingPdusUsed;
				}
				set
				{
					_LegacyAdvertisingPdusUsed = value;
				}
			}

			public AdvertisingDataStatusEnum DataStatus
			{
				get
				{
					return _DataStatus;
				}
				set
				{
					_DataStatus = value;
				}
			}
		}

		public static class EventTypeInfo
		{
			public static EventTypeEnumCollection ValueToEventType(uint value)
			{
				EventTypeEnumCollection eventTypeEnumCollection = new EventTypeEnumCollection();
				eventTypeEnumCollection.ConnectableAdvertising = AssertBitInfo.ValueToAssertBit(value & 1u);
				eventTypeEnumCollection.ScannableAdvertising = AssertBitInfo.ValueToAssertBit((value & 2) >> 1);
				eventTypeEnumCollection.DirectedAdvertising = AssertBitInfo.ValueToAssertBit((value & 4) >> 2);
				eventTypeEnumCollection.ScanResponse = AssertBitInfo.ValueToAssertBit((value & 8) >> 3);
				eventTypeEnumCollection.LegacyAdvertisingPdusUsed = AssertBitInfo.ValueToAssertBit((value & 0x10) >> 4);
				eventTypeEnumCollection.DataStatus = AdvertisingDataStatusInfo.ValueToAdvertisingDataStatus((value & 0x60) >> 5);
				return eventTypeEnumCollection;
			}

			public static uint EventTypeToValue(EventTypeEnumCollection enumCollection)
			{
				uint num = 0u;
				num |= AssertBitInfo.AssertBitToValue(enumCollection.ConnectableAdvertising);
				num |= AssertBitInfo.AssertBitToValue(enumCollection.ScannableAdvertising) << 1;
				num |= AssertBitInfo.AssertBitToValue(enumCollection.DirectedAdvertising) << 2;
				num |= AssertBitInfo.AssertBitToValue(enumCollection.ScanResponse) << 3;
				num |= AssertBitInfo.AssertBitToValue(enumCollection.LegacyAdvertisingPdusUsed) << 4;
				return num | (AdvertisingDataStatusInfo.AdvertisingDataStatusToValue(enumCollection.DataStatus) << 5);
			}

			public static string EventTypeToString(EventTypeEnumCollection enumCollection)
			{
				string text = "";
				text = text + "Connectable advertising: " + AssertBitInfo.AssertBitToString(enumCollection.ConnectableAdvertising) + "\r\n";
				text = text + "Scannable advertising: " + AssertBitInfo.AssertBitToString(enumCollection.ScannableAdvertising) + "\r\n";
				text = text + "Directed advertising: " + AssertBitInfo.AssertBitToString(enumCollection.DirectedAdvertising) + "\r\n";
				text = text + "Scan response: " + AssertBitInfo.AssertBitToString(enumCollection.ScanResponse) + "\r\n";
				text = text + "Legacy advertising PDUs used: " + AssertBitInfo.AssertBitToString(enumCollection.LegacyAdvertisingPdusUsed) + "\r\n";
				text = text + "Data status: " + AdvertisingDataStatusInfo.AdvertisingDataStatusToString(enumCollection.DataStatus) + "\r\n";
				return text.TrimEnd('\r', '\n');
			}

			public static string EventTypeToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("Bit 0: Connectable advertising");
				stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
				stringBuilder.AppendLine("Bit 1: Scannable advertising");
				stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
				stringBuilder.AppendLine("Bit 2: Directed advertising");
				stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
				stringBuilder.AppendLine("Bit 3: Scan response");
				stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
				stringBuilder.AppendLine("Bit 4: Legacy advertising PDUs used");
				stringBuilder.AppendLine(AssertBitInfo.AssertBitToDescription());
				stringBuilder.AppendLine("Bits 6-5: Data status");
				stringBuilder.AppendLine(AdvertisingDataStatusInfo.AdvertisingDataStatusToDescription());
				stringBuilder.AppendLine("Bits 15-7: Reserved for future use");
				return stringBuilder.ToString();
			}
		}

		public enum PrimaryPhyEnum
		{
			Reserved_for_future_use,
			InvalidPrimaryPhyValue
		}

		public static class PrimaryPhyInfo
		{
			public static PrimaryPhyEnum ValueToPrimaryPhy(uint value)
			{
				if (value == 2)
				{
					return PrimaryPhyEnum.Reserved_for_future_use;
				}
				return PrimaryPhyEnum.InvalidPrimaryPhyValue;
			}

			public static uint PrimaryPhyToValue(PrimaryPhyEnum enumItem)
			{
				if (enumItem == PrimaryPhyEnum.Reserved_for_future_use)
				{
					return 2u;
				}
				return uint.MaxValue;
			}

			public static string PrimaryPhyToString(PrimaryPhyEnum enumItem)
			{
				if (enumItem == PrimaryPhyEnum.Reserved_for_future_use)
				{
					return "Reserved for future use";
				}
				return "Invalid PrimaryPhy Value";
			}

			public static string PrimaryPhyToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x2 = Reserved for future use");
				return stringBuilder.ToString();
			}
		}

		public enum SecondaryPhyEnum
		{
			No_packets_on_the_secondary_advertising_channel,
			InvalidSecondaryPhyValue
		}

		public static class SecondaryPhyInfo
		{
			public static SecondaryPhyEnum ValueToSecondaryPhy(uint value)
			{
				if (value == 0)
				{
					return SecondaryPhyEnum.No_packets_on_the_secondary_advertising_channel;
				}
				return SecondaryPhyEnum.InvalidSecondaryPhyValue;
			}

			public static uint SecondaryPhyToValue(SecondaryPhyEnum enumItem)
			{
				if (enumItem == SecondaryPhyEnum.No_packets_on_the_secondary_advertising_channel)
				{
					return 0u;
				}
				return uint.MaxValue;
			}

			public static string SecondaryPhyToString(SecondaryPhyEnum enumItem)
			{
				if (enumItem == SecondaryPhyEnum.No_packets_on_the_secondary_advertising_channel)
				{
					return "No packets on the secondary advertising channel";
				}
				return "Invalid SecondaryPhy Value";
			}

			public static string SecondaryPhyToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = No packets on the secondary advertising channel");
				return stringBuilder.ToString();
			}
		}

		public enum AdvertisingSidEnum
		{
			Value_of_the_Advertising_SID_subfield_in_the_ADI_field_of_the_PDU,
			Reserved_for_future_use,
			No_ADI_field_in_the_PDU,
			InvalidAdvertisingSidValue
		}

		public static class AdvertisingSidInfo
		{
			public static AdvertisingSidEnum ValueToAdvertisingSid(uint value)
			{
				if (value >= 0 && value <= 15)
				{
					return AdvertisingSidEnum.Value_of_the_Advertising_SID_subfield_in_the_ADI_field_of_the_PDU;
				}
				if (value >= 16 && value <= 254)
				{
					return AdvertisingSidEnum.Reserved_for_future_use;
				}
				if (value == 255)
				{
					return AdvertisingSidEnum.No_ADI_field_in_the_PDU;
				}
				return AdvertisingSidEnum.InvalidAdvertisingSidValue;
			}

			public static uint AdvertisingSidToValue(AdvertisingSidEnum enumItem)
			{
				return enumItem switch
				{
					AdvertisingSidEnum.Value_of_the_Advertising_SID_subfield_in_the_ADI_field_of_the_PDU => 0u, 
					AdvertisingSidEnum.Reserved_for_future_use => 16u, 
					AdvertisingSidEnum.No_ADI_field_in_the_PDU => 255u, 
					_ => uint.MaxValue, 
				};
			}

			public static string AdvertisingSidToString(AdvertisingSidEnum enumItem)
			{
				return enumItem switch
				{
					AdvertisingSidEnum.Value_of_the_Advertising_SID_subfield_in_the_ADI_field_of_the_PDU => "Value of the Advertising SID subfield in the ADI field of the PDU", 
					AdvertisingSidEnum.Reserved_for_future_use => "Reserved for future use.", 
					AdvertisingSidEnum.No_ADI_field_in_the_PDU => "No ADI field in the PDU", 
					_ => "Invalid AdvertisingSid Value", 
				};
			}

			public static string AdvertisingSidToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0-0xF = Value of the Advertising SID subfield in the ADI field of the PDU");
				stringBuilder.AppendLine("0x10-0xFE = Reserved for future use.");
				stringBuilder.AppendLine("0xFF = No ADI field in the PDU");
				return stringBuilder.ToString();
			}
		}

		public enum PeriodicAdvertisingIntervalEnum
		{
			No_periodic_advertising,
			InvalidPeriodicAdvertisingIntervalValue
		}

		public static class PeriodicAdvertisingIntervalInfo
		{
			public static PeriodicAdvertisingIntervalEnum ValueToPeriodicAdvertisingInterval(uint value)
			{
				if (value == 0)
				{
					return PeriodicAdvertisingIntervalEnum.No_periodic_advertising;
				}
				return PeriodicAdvertisingIntervalEnum.InvalidPeriodicAdvertisingIntervalValue;
			}

			public static uint PeriodicAdvertisingIntervalToValue(PeriodicAdvertisingIntervalEnum enumItem)
			{
				if (enumItem == PeriodicAdvertisingIntervalEnum.No_periodic_advertising)
				{
					return 0u;
				}
				return uint.MaxValue;
			}

			public static string PeriodicAdvertisingIntervalToString(PeriodicAdvertisingIntervalEnum enumItem)
			{
				if (enumItem == PeriodicAdvertisingIntervalEnum.No_periodic_advertising)
				{
					return "No periodic advertising";
				}
				return "Invalid PeriodicAdvertisingInterval Value";
			}

			public static string PeriodicAdvertisingIntervalToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0x0 = No periodic advertising");
				return stringBuilder.ToString();
			}
		}

		public enum DirectAddressTypeEnum
		{
			Random_Device_Address_Controller_unable_to_resolve,
			InvalidDirectAddressTypeValue
		}

		public static class DirectAddressTypeInfo
		{
			public static DirectAddressTypeEnum ValueToDirectAddressType(uint value)
			{
				if (value == 255)
				{
					return DirectAddressTypeEnum.Random_Device_Address_Controller_unable_to_resolve;
				}
				return DirectAddressTypeEnum.InvalidDirectAddressTypeValue;
			}

			public static uint DirectAddressTypeToValue(DirectAddressTypeEnum enumItem)
			{
				if (enumItem == DirectAddressTypeEnum.Random_Device_Address_Controller_unable_to_resolve)
				{
					return 255u;
				}
				return uint.MaxValue;
			}

			public static string DirectAddressTypeToString(DirectAddressTypeEnum enumItem)
			{
				if (enumItem == DirectAddressTypeEnum.Random_Device_Address_Controller_unable_to_resolve)
				{
					return "Random Device Address (Controller unable to resolve)";
				}
				return "Invalid DirectAddressType Value";
			}

			public static string DirectAddressTypeToDescription()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("0xFF = Random Device Address (Controller unable to resolve)");
				return stringBuilder.ToString();
			}
		}

		private uint _EventType;

		private uint _AddressType;

		private ulong _Address;

		private uint _PrimaryPhy;

		private uint _SecondaryPhy;

		private uint _AdvertisingSid;

		private uint _TxPower;

		private uint _Rssi;

		private uint _PeriodicAdvertisingInterval;

		private uint _DirectAddressType;

		private ulong _DirectAddress;

		private uint _DataLength;

		private List<uint> _DataList = new List<uint>();

		public uint EventType
		{
			get
			{
				return _EventType;
			}
			set
			{
				if (value > 65535)
				{
					throw new Exception("Maximum possible value for EventType is 0xFFFF");
				}
				_EventType = value;
			}
		}

		public uint AddressType
		{
			get
			{
				return _AddressType;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for AddressType is 0xFF");
				}
				_AddressType = value;
			}
		}

		public ulong Address
		{
			get
			{
				return _Address;
			}
			set
			{
				_Address = value;
			}
		}

		public uint PrimaryPhy
		{
			get
			{
				return _PrimaryPhy;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for PrimaryPhy is 0xFF");
				}
				_PrimaryPhy = value;
			}
		}

		public uint SecondaryPhy
		{
			get
			{
				return _SecondaryPhy;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for SecondaryPhy is 0xFF");
				}
				_SecondaryPhy = value;
			}
		}

		public uint AdvertisingSid
		{
			get
			{
				return _AdvertisingSid;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for AdvertisingSid is 0xFF");
				}
				_AdvertisingSid = value;
			}
		}

		public uint TxPower
		{
			get
			{
				return _TxPower;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for TxPower is 0xFF");
				}
				_TxPower = value;
			}
		}

		public uint Rssi
		{
			get
			{
				return _Rssi;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for Rssi is 0xFF");
				}
				_Rssi = value;
			}
		}

		public uint PeriodicAdvertisingInterval
		{
			get
			{
				return _PeriodicAdvertisingInterval;
			}
			set
			{
				if (value > 65535)
				{
					throw new Exception("Maximum possible value for PeriodicAdvertisingInterval is 0xFFFF");
				}
				_PeriodicAdvertisingInterval = value;
			}
		}

		public uint DirectAddressType
		{
			get
			{
				return _DirectAddressType;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for DirectAddressType is 0xFF");
				}
				_DirectAddressType = value;
			}
		}

		public ulong DirectAddress
		{
			get
			{
				return _DirectAddress;
			}
			set
			{
				_DirectAddress = value;
			}
		}

		public uint DataLength
		{
			get
			{
				return _DataLength;
			}
			set
			{
				if (value > 255)
				{
					throw new Exception("Maximum possible value for DataLength is 0xFF");
				}
				_DataLength = value;
				while (_DataList.Count < _DataLength)
				{
					_DataList.Add(0u);
				}
				while (_DataList.Count > _DataLength)
				{
					_DataList.RemoveAt(_DataList.Count - 1);
				}
			}
		}

		public List<uint> DataList => _DataList;

		public void SetDefaultValues()
		{
			DataLength = 0u;
		}

		public EventTypeEnumCollection GetEventTypeAsEventTypeEnumCollection()
		{
			return EventTypeInfo.ValueToEventType(_EventType);
		}

		public void SetEventTypeAsEventTypeEnumCollection(EventTypeEnumCollection enumCollection)
		{
			EventType = EventTypeInfo.EventTypeToValue(enumCollection);
		}

		public AdvertisingReportAddressTypeEnum GetAddressTypeAsAdvertisingReportAddressTypeEnum()
		{
			return AdvertisingReportAddressTypeInfo.ValueToAdvertisingReportAddressType(_AddressType);
		}

		public void SetAddressTypeAsAdvertisingReportAddressTypeEnum(AdvertisingReportAddressTypeEnum enumItem)
		{
			AddressType = AdvertisingReportAddressTypeInfo.AdvertisingReportAddressTypeToValue(enumItem);
		}

		public AdvertisingPhyEnum GetPrimaryPhyAsAdvertisingPhyEnum()
		{
			if ((_PrimaryPhy < 0 || _PrimaryPhy > 1) && (_PrimaryPhy < 3 || _PrimaryPhy > 255))
			{
				throw new Exception("Primary_PHY is not in the range 0x00-0x01 and not in the range 0x03-0xFF, can not get Primary_PHY as AdvertisingPhyEnum");
			}
			return AdvertisingPhyInfo.ValueToAdvertisingPhy(_PrimaryPhy);
		}

		public void SetPrimaryPhyAsAdvertisingPhyEnum(AdvertisingPhyEnum enumItem)
		{
			PrimaryPhy = AdvertisingPhyInfo.AdvertisingPhyToValue(enumItem);
		}

		public PrimaryPhyEnum GetPrimaryPhyAsPrimaryPhyEnum()
		{
			if (_PrimaryPhy != 2)
			{
				throw new Exception("Primary_PHY is not 0x02, can not get Primary_PHY as PrimaryPhyEnum");
			}
			return PrimaryPhyInfo.ValueToPrimaryPhy(_PrimaryPhy);
		}

		public void SetPrimaryPhyAsPrimaryPhyEnum(PrimaryPhyEnum enumItem)
		{
			PrimaryPhy = PrimaryPhyInfo.PrimaryPhyToValue(enumItem);
		}

		public SecondaryPhyEnum GetSecondaryPhyAsSecondaryPhyEnum()
		{
			if (_SecondaryPhy != 0)
			{
				throw new Exception("Secondary_PHY is not 0x00, can not get Secondary_PHY as SecondaryPhyEnum");
			}
			return SecondaryPhyInfo.ValueToSecondaryPhy(_SecondaryPhy);
		}

		public void SetSecondaryPhyAsSecondaryPhyEnum(SecondaryPhyEnum enumItem)
		{
			SecondaryPhy = SecondaryPhyInfo.SecondaryPhyToValue(enumItem);
		}

		public AdvertisingPhyEnum GetSecondaryPhyAsAdvertisingPhyEnum()
		{
			if (_SecondaryPhy < 1 || _SecondaryPhy > 255)
			{
				throw new Exception("Secondary_PHY is not in the range 0x01-0xFF, can not get Secondary_PHY as AdvertisingPhyEnum");
			}
			return AdvertisingPhyInfo.ValueToAdvertisingPhy(_SecondaryPhy);
		}

		public void SetSecondaryPhyAsAdvertisingPhyEnum(AdvertisingPhyEnum enumItem)
		{
			SecondaryPhy = AdvertisingPhyInfo.AdvertisingPhyToValue(enumItem);
		}

		public AdvertisingReportTxPowerEnum GetTxPowerAsAdvertisingReportTxPowerEnum()
		{
			return AdvertisingReportTxPowerInfo.ValueToAdvertisingReportTxPower(_TxPower);
		}

		public void SetTxPowerAsAdvertisingReportTxPowerEnum(AdvertisingReportTxPowerEnum enumItem)
		{
			TxPower = AdvertisingReportTxPowerInfo.AdvertisingReportTxPowerToValue(enumItem);
		}

		public AdvertisingRssiEnum GetRssiAsAdvertisingRssiEnum()
		{
			return AdvertisingRssiInfo.ValueToAdvertisingRssi(_Rssi);
		}

		public void SetRssiAsAdvertisingRssiEnum(AdvertisingRssiEnum enumItem)
		{
			Rssi = AdvertisingRssiInfo.AdvertisingRssiToValue(enumItem);
		}

		public PeriodicAdvertisingIntervalEnum GetPeriodicAdvertisingIntervalAsPeriodicAdvertisingIntervalEnum()
		{
			return PeriodicAdvertisingIntervalInfo.ValueToPeriodicAdvertisingInterval(_PeriodicAdvertisingInterval);
		}

		public void SetPeriodicAdvertisingIntervalAsPeriodicAdvertisingIntervalEnum(PeriodicAdvertisingIntervalEnum enumItem)
		{
			PeriodicAdvertisingInterval = PeriodicAdvertisingIntervalInfo.PeriodicAdvertisingIntervalToValue(enumItem);
		}

		public PeerResolvableAddressTypeEnum GetDirectAddressTypeAsPeerResolvableAddressTypeEnum()
		{
			if (_DirectAddressType < 0 || _DirectAddressType > 254)
			{
				throw new Exception("Direct_Address_Type is not in the range 0x00-0xFE, can not get Direct_Address_Type as PeerResolvableAddressTypeEnum");
			}
			return PeerResolvableAddressTypeInfo.ValueToPeerResolvableAddressType(_DirectAddressType);
		}

		public void SetDirectAddressTypeAsPeerResolvableAddressTypeEnum(PeerResolvableAddressTypeEnum enumItem)
		{
			DirectAddressType = PeerResolvableAddressTypeInfo.PeerResolvableAddressTypeToValue(enumItem);
		}

		public DirectAddressTypeEnum GetDirectAddressTypeAsDirectAddressTypeEnum()
		{
			if (_DirectAddressType != 255)
			{
				throw new Exception("Direct_Address_Type is not 0xFF, can not get Direct_Address_Type as DirectAddressTypeEnum");
			}
			return DirectAddressTypeInfo.ValueToDirectAddressType(_DirectAddressType);
		}

		public void SetDirectAddressTypeAsDirectAddressTypeEnum(DirectAddressTypeEnum enumItem)
		{
			DirectAddressType = DirectAddressTypeInfo.DirectAddressTypeToValue(enumItem);
		}

		public bool FromBitBuilder(ref BitBuilder bitBuilder)
		{
			EventType = bitBuilder.RemoveBitsAsUintLittleEndian(16);
			AddressType = bitBuilder.RemoveBitsAsUint(8);
			Address = bitBuilder.RemoveBitsAsUlongLittleEndian(48);
			PrimaryPhy = bitBuilder.RemoveBitsAsUint(8);
			SecondaryPhy = bitBuilder.RemoveBitsAsUint(8);
			AdvertisingSid = bitBuilder.RemoveBitsAsUint(8);
			TxPower = bitBuilder.RemoveBitsAsUint(8);
			Rssi = bitBuilder.RemoveBitsAsUint(8);
			PeriodicAdvertisingInterval = bitBuilder.RemoveBitsAsUintLittleEndian(16);
			DirectAddressType = bitBuilder.RemoveBitsAsUint(8);
			DirectAddress = bitBuilder.RemoveBitsAsUlongLittleEndian(48);
			DataLength = bitBuilder.RemoveBitsAsUint(8);
			for (int i = 0; i < DataList.Count; i++)
			{
				DataList[i] = bitBuilder.RemoveBitsAsUint(8);
			}
			return true;
		}

		public string ToBitString()
		{
			BitBuilder bitBuilder = new BitBuilder();
			bitBuilder.AddBitsAsUintLittleEndian(EventType, 16);
			bitBuilder.AddBitsAsUint(AddressType, 8);
			bitBuilder.AddBitsAsUlongLittleEndian(Address, 48);
			bitBuilder.AddBitsAsUint(PrimaryPhy, 8);
			bitBuilder.AddBitsAsUint(SecondaryPhy, 8);
			bitBuilder.AddBitsAsUint(AdvertisingSid, 8);
			bitBuilder.AddBitsAsUint(TxPower, 8);
			bitBuilder.AddBitsAsUint(Rssi, 8);
			bitBuilder.AddBitsAsUintLittleEndian(PeriodicAdvertisingInterval, 16);
			bitBuilder.AddBitsAsUint(DirectAddressType, 8);
			bitBuilder.AddBitsAsUlongLittleEndian(DirectAddress, 48);
			bitBuilder.AddBitsAsUint(DataLength, 8);
			for (int i = 0; i < DataList.Count; i++)
			{
				if (DataList[i] > 255)
				{
					throw new Exception("DataList[i] is > 0xFF");
				}
				bitBuilder.AddBitsAsUint(DataList[i], 8);
			}
			return bitBuilder.ToString();
		}

		public List<string> GetWarnings()
		{
			List<string> list = new List<string>();
			if (DataLength < 0)
			{
				list.Add("Minimum allowed value for Data_Length is 0x0");
			}
			if (DataLength > 229)
			{
				list.Add("Maximum allowed value for Data_Length is 0xE5");
			}
			return list;
		}
	}

	private const uint _EventCode = 62u;

	private Type[] expectedResponseTypes = new Type[0];

	private PacketInfoBase info;

	private uint _PayloadLength;

	public UserFieldsWrapper _UserFields = new UserFieldsWrapper();

	public override PacketType Type => PacketType.Notification;

	public override Type[] ExpectedResponseTypes => expectedResponseTypes;

	public override PacketInfoBase Info
	{
		get
		{
			if (info == null)
			{
				info = new LeExtendedAdvertisingReportInfo(this);
			}
			return info;
		}
	}

	public uint EventCode => 62u;

	public uint PayloadLength
	{
		get
		{
			ToBitString();
			return _PayloadLength;
		}
	}

	public UserFieldsWrapper UserFields => _UserFields;

	protected override bool FromBitBuilder(ref BitBuilder bitBuilder)
	{
		if (bitBuilder.RemoveBitsAsUint(8) != EventCode)
		{
			return false;
		}
		_PayloadLength = bitBuilder.RemoveBitsAsUint(8);
		int numberOfBits = bitBuilder.GetNumberOfBits();
		if (numberOfBits > _PayloadLength * 8 + 7)
		{
			return false;
		}
		if (numberOfBits < _PayloadLength * 8)
		{
			return false;
		}
		if (bitBuilder.RemoveBitsAsUint(8) != UserFields.SubeventCode)
		{
			return false;
		}
		UserFields.NumReports = bitBuilder.RemoveBitsAsUint(8);
		for (int i = 0; i < UserFields.ReportsList.Count; i++)
		{
			UserFields.ReportsList[i].FromBitBuilder(ref bitBuilder);
		}
		if (bitBuilder.GetNumberOfBits() > 7)
		{
			return false;
		}
		return true;
	}

	public override string ToBitString()
	{
		BitBuilder bitBuilder = new BitBuilder();
		bitBuilder.AddBitsAsUint(EventCode, 8);
		int numberOfBits = bitBuilder.GetNumberOfBits();
		bitBuilder.AddBitsAsUint(0u, 8);
		bitBuilder.AddBitsAsUint(UserFields.SubeventCode, 8);
		bitBuilder.AddBitsAsUint(UserFields.NumReports, 8);
		for (int i = 0; i < UserFields.ReportsList.Count; i++)
		{
			bitBuilder.AddBitsAsString(UserFields.ReportsList[i].ToBitString());
		}
		_PayloadLength = (uint)((bitBuilder.GetNumberOfBits() - numberOfBits - 8) / 8);
		if ((bitBuilder.GetNumberOfBits() - numberOfBits - 8) % 8 != 0)
		{
			_PayloadLength++;
		}
		bitBuilder.ChangeBitsAsUint(numberOfBits, _PayloadLength, 8);
		return bitBuilder.ToString();
	}
}
