using System.Text;

namespace QCRPG.TSL.BT.Packets;

public static class LeFeaturesInfo
{
	public static LeFeaturesEnumCollection ValueToLeFeatures(ulong value)
	{
		LeFeaturesEnumCollection leFeaturesEnumCollection = new LeFeaturesEnumCollection();
		leFeaturesEnumCollection.LeEncryption = SupportBitInfo.ValueToSupportBit((uint)(value & 1));
		leFeaturesEnumCollection.ConnectionParametersRequestProcedure = SupportBitInfo.ValueToSupportBit((uint)((value & 2) >> 1));
		leFeaturesEnumCollection.ExtendedRejectIndication = SupportBitInfo.ValueToSupportBit((uint)((value & 4) >> 2));
		leFeaturesEnumCollection.SlaveInitiatedFeaturesExchange = SupportBitInfo.ValueToSupportBit((uint)((value & 8) >> 3));
		leFeaturesEnumCollection.LePing = SupportBitInfo.ValueToSupportBit((uint)((value & 0x10) >> 4));
		leFeaturesEnumCollection.LeDataPacketLengthExtension = SupportBitInfo.ValueToSupportBit((uint)((value & 0x20) >> 5));
		leFeaturesEnumCollection.LlPrivacy = SupportBitInfo.ValueToSupportBit((uint)((value & 0x40) >> 6));
		leFeaturesEnumCollection.ExtendedScannerFilterPolicies = SupportBitInfo.ValueToSupportBit((uint)((value & 0x80) >> 7));
		leFeaturesEnumCollection.Le2mPhy = SupportBitInfo.ValueToSupportBit((uint)((value & 0x100) >> 8));
		leFeaturesEnumCollection.StableModulationIndexTransmitter = SupportBitInfo.ValueToSupportBit((uint)((value & 0x200) >> 9));
		leFeaturesEnumCollection.StableModulationIndexReceiver = SupportBitInfo.ValueToSupportBit((uint)((value & 0x400) >> 10));
		leFeaturesEnumCollection.LeCodedPhy = SupportBitInfo.ValueToSupportBit((uint)((value & 0x800) >> 11));
		leFeaturesEnumCollection.LeExtendedAdvertising = SupportBitInfo.ValueToSupportBit((uint)((value & 0x1000) >> 12));
		leFeaturesEnumCollection.LePeriodicAdvertising = SupportBitInfo.ValueToSupportBit((uint)((value & 0x2000) >> 13));
		leFeaturesEnumCollection.ChannelSelectionAlgorithm2 = SupportBitInfo.ValueToSupportBit((uint)((value & 0x4000) >> 14));
		leFeaturesEnumCollection.LePowerClass1 = SupportBitInfo.ValueToSupportBit((uint)((value & 0x8000) >> 15));
		leFeaturesEnumCollection.MinimumNumberOfUsedChannelsProcedure = SupportBitInfo.ValueToSupportBit((uint)((value & 0x10000) >> 16));
		leFeaturesEnumCollection.ConnectionSupplementalRequest = SupportBitInfo.ValueToSupportBit((uint)((value & 0x20000) >> 17));
		leFeaturesEnumCollection.ConnectionSupplementalResponse = SupportBitInfo.ValueToSupportBit((uint)((value & 0x40000) >> 18));
		leFeaturesEnumCollection.ConnectionlessSupplementalTransmitter = SupportBitInfo.ValueToSupportBit((uint)((value & 0x80000) >> 19));
		leFeaturesEnumCollection.ConnectionlessSupplementalReceiver = SupportBitInfo.ValueToSupportBit((uint)((value & 0x100000) >> 20));
		leFeaturesEnumCollection.AntennaSwitchingDuringSupplementalTransmissionAod = SupportBitInfo.ValueToSupportBit((uint)((value & 0x200000) >> 21));
		leFeaturesEnumCollection.AntennaSwitchingDuringSupplementalReceptionAoa = SupportBitInfo.ValueToSupportBit((uint)((value & 0x400000) >> 22));
		leFeaturesEnumCollection.ReceivingConstantToneExtensions = SupportBitInfo.ValueToSupportBit((uint)((value & 0x800000) >> 23));
		leFeaturesEnumCollection.PeriodicAdvertisingSyncTransferSender = SupportBitInfo.ValueToSupportBit((uint)((value & 0x1000000) >> 24));
		leFeaturesEnumCollection.PeriodicAdvertisingSyncTransferRecipient = SupportBitInfo.ValueToSupportBit((uint)((value & 0x2000000) >> 25));
		leFeaturesEnumCollection.SleepClockAccuracyUpdates = SupportBitInfo.ValueToSupportBit((uint)((value & 0x4000000) >> 26));
		leFeaturesEnumCollection.RemotePublicKeyValidation = SupportBitInfo.ValueToSupportBit((uint)((value & 0x8000000) >> 27));
		leFeaturesEnumCollection.ConnectedIsochronousStreamMaster = SupportBitInfo.ValueToSupportBit((uint)((value & 0x10000000) >> 28));
		leFeaturesEnumCollection.ConnectedIsochronousStreamSlave = SupportBitInfo.ValueToSupportBit((uint)((value & 0x20000000) >> 29));
		leFeaturesEnumCollection.IsochronousBroadcaster = SupportBitInfo.ValueToSupportBit((uint)((value & 0x40000000) >> 30));
		leFeaturesEnumCollection.SynchronizedReceiver = SupportBitInfo.ValueToSupportBit((uint)((value & 0x80000000u) >> 31));
		leFeaturesEnumCollection.IsochronousChannelsHostSupport = SupportBitInfo.ValueToSupportBit((uint)((value & 0x100000000L) >> 32));
		leFeaturesEnumCollection.LePowerControlRequest = SupportBitInfo.ValueToSupportBit((uint)((value & 0x200000000L) >> 33));
		leFeaturesEnumCollection.LePowerChangeIndication = SupportBitInfo.ValueToSupportBit((uint)((value & 0x400000000L) >> 34));
		leFeaturesEnumCollection.LePathLossMonitoring = SupportBitInfo.ValueToSupportBit((uint)((value & 0x800000000L) >> 35));
		return leFeaturesEnumCollection;
	}

	public static ulong LeFeaturesToValue(LeFeaturesEnumCollection enumCollection)
	{
		ulong num = 0uL;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.LeEncryption);
		num |= SupportBitInfo.SupportBitToValue(enumCollection.ConnectionParametersRequestProcedure) << 1;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.ExtendedRejectIndication) << 2;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.SlaveInitiatedFeaturesExchange) << 3;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.LePing) << 4;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.LeDataPacketLengthExtension) << 5;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.LlPrivacy) << 6;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.ExtendedScannerFilterPolicies) << 7;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.Le2mPhy) << 8;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.StableModulationIndexTransmitter) << 9;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.StableModulationIndexReceiver) << 10;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.LeCodedPhy) << 11;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.LeExtendedAdvertising) << 12;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.LePeriodicAdvertising) << 13;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.ChannelSelectionAlgorithm2) << 14;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.LePowerClass1) << 15;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.MinimumNumberOfUsedChannelsProcedure) << 16;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.ConnectionSupplementalRequest) << 17;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.ConnectionSupplementalResponse) << 18;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.ConnectionlessSupplementalTransmitter) << 19;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.ConnectionlessSupplementalReceiver) << 20;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.AntennaSwitchingDuringSupplementalTransmissionAod) << 21;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.AntennaSwitchingDuringSupplementalReceptionAoa) << 22;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.ReceivingConstantToneExtensions) << 23;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.PeriodicAdvertisingSyncTransferSender) << 24;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.PeriodicAdvertisingSyncTransferRecipient) << 25;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.SleepClockAccuracyUpdates) << 26;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.RemotePublicKeyValidation) << 27;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.ConnectedIsochronousStreamMaster) << 28;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.ConnectedIsochronousStreamSlave) << 29;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.IsochronousBroadcaster) << 30;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.SynchronizedReceiver) << 31;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.IsochronousChannelsHostSupport);
		num |= SupportBitInfo.SupportBitToValue(enumCollection.LePowerControlRequest) << 1;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.LePowerChangeIndication) << 2;
		return num | (SupportBitInfo.SupportBitToValue(enumCollection.LePathLossMonitoring) << 3);
	}

	public static string LeFeaturesToString(LeFeaturesEnumCollection enumCollection)
	{
		string text = "";
		text = text + "LE Encryption: " + SupportBitInfo.SupportBitToString(enumCollection.LeEncryption) + "\r\n";
		text = text + "Connection Parameters Request Procedure: " + SupportBitInfo.SupportBitToString(enumCollection.ConnectionParametersRequestProcedure) + "\r\n";
		text = text + "Extended Reject Indication: " + SupportBitInfo.SupportBitToString(enumCollection.ExtendedRejectIndication) + "\r\n";
		text = text + "Slave-initiated Features Exchange: " + SupportBitInfo.SupportBitToString(enumCollection.SlaveInitiatedFeaturesExchange) + "\r\n";
		text = text + "LE Ping: " + SupportBitInfo.SupportBitToString(enumCollection.LePing) + "\r\n";
		text = text + "LE Data Packet Length Extension: " + SupportBitInfo.SupportBitToString(enumCollection.LeDataPacketLengthExtension) + "\r\n";
		text = text + "LL Privacy: " + SupportBitInfo.SupportBitToString(enumCollection.LlPrivacy) + "\r\n";
		text = text + "Extended Scanner Filter Policies: " + SupportBitInfo.SupportBitToString(enumCollection.ExtendedScannerFilterPolicies) + "\r\n";
		text = text + "LE 2M PHY: " + SupportBitInfo.SupportBitToString(enumCollection.Le2mPhy) + "\r\n";
		text = text + "Stable Modulation Index - Transmitter: " + SupportBitInfo.SupportBitToString(enumCollection.StableModulationIndexTransmitter) + "\r\n";
		text = text + "Stable Modulation Index - Receiver: " + SupportBitInfo.SupportBitToString(enumCollection.StableModulationIndexReceiver) + "\r\n";
		text = text + "LE Coded PHY: " + SupportBitInfo.SupportBitToString(enumCollection.LeCodedPhy) + "\r\n";
		text = text + "LE Extended Advertising: " + SupportBitInfo.SupportBitToString(enumCollection.LeExtendedAdvertising) + "\r\n";
		text = text + "LE Periodic Advertising: " + SupportBitInfo.SupportBitToString(enumCollection.LePeriodicAdvertising) + "\r\n";
		text = text + "Channel Selection Algorithm 2: " + SupportBitInfo.SupportBitToString(enumCollection.ChannelSelectionAlgorithm2) + "\r\n";
		text = text + "LE Power Class 1: " + SupportBitInfo.SupportBitToString(enumCollection.LePowerClass1) + "\r\n";
		text = text + "Minimum Number of Used Channels Procedure: " + SupportBitInfo.SupportBitToString(enumCollection.MinimumNumberOfUsedChannelsProcedure) + "\r\n";
		text = text + "Connection Supplemental Request: " + SupportBitInfo.SupportBitToString(enumCollection.ConnectionSupplementalRequest) + "\r\n";
		text = text + "Connection Supplemental Response: " + SupportBitInfo.SupportBitToString(enumCollection.ConnectionSupplementalResponse) + "\r\n";
		text = text + "Connectionless Supplemental Transmitter: " + SupportBitInfo.SupportBitToString(enumCollection.ConnectionlessSupplementalTransmitter) + "\r\n";
		text = text + "Connectionless Supplemental Receiver: " + SupportBitInfo.SupportBitToString(enumCollection.ConnectionlessSupplementalReceiver) + "\r\n";
		text = text + "Antenna Switching During Supplemental Transmission AoD: " + SupportBitInfo.SupportBitToString(enumCollection.AntennaSwitchingDuringSupplementalTransmissionAod) + "\r\n";
		text = text + "Antenna Switching During Supplemental Reception AoA: " + SupportBitInfo.SupportBitToString(enumCollection.AntennaSwitchingDuringSupplementalReceptionAoa) + "\r\n";
		text = text + "Receiving Constant Tone Extensions: " + SupportBitInfo.SupportBitToString(enumCollection.ReceivingConstantToneExtensions) + "\r\n";
		text = text + "Periodic Advertising Sync Transfer Sender: " + SupportBitInfo.SupportBitToString(enumCollection.PeriodicAdvertisingSyncTransferSender) + "\r\n";
		text = text + "Periodic Advertising Sync Transfer Recipient: " + SupportBitInfo.SupportBitToString(enumCollection.PeriodicAdvertisingSyncTransferRecipient) + "\r\n";
		text = text + "Sleep Clock Accuracy Updates: " + SupportBitInfo.SupportBitToString(enumCollection.SleepClockAccuracyUpdates) + "\r\n";
		text = text + "Remote Public Key Validation: " + SupportBitInfo.SupportBitToString(enumCollection.RemotePublicKeyValidation) + "\r\n";
		text = text + "Connected Isochronous Stream Master: " + SupportBitInfo.SupportBitToString(enumCollection.ConnectedIsochronousStreamMaster) + "\r\n";
		text = text + "Connected Isochronous Stream Slave: " + SupportBitInfo.SupportBitToString(enumCollection.ConnectedIsochronousStreamSlave) + "\r\n";
		text = text + "Isochronous Broadcaster: " + SupportBitInfo.SupportBitToString(enumCollection.IsochronousBroadcaster) + "\r\n";
		text = text + "Synchronized Receiver: " + SupportBitInfo.SupportBitToString(enumCollection.SynchronizedReceiver) + "\r\n";
		text = text + "Isochronous Channels Host Support: " + SupportBitInfo.SupportBitToString(enumCollection.IsochronousChannelsHostSupport) + "\r\n";
		text = text + "LE Power Control Request: " + SupportBitInfo.SupportBitToString(enumCollection.LePowerControlRequest) + "\r\n";
		text = text + "LE Power Change Indication: " + SupportBitInfo.SupportBitToString(enumCollection.LePowerChangeIndication) + "\r\n";
		text = text + "LE Path Loss Monitoring: " + SupportBitInfo.SupportBitToString(enumCollection.LePathLossMonitoring) + "\r\n";
		return text.TrimEnd('\r', '\n');
	}

	public static string LeFeaturesToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("Bit 0: LE Encryption");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 1: Connection Parameters Request Procedure");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 2: Extended Reject Indication");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 3: Slave-initiated Features Exchange");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 4: LE Ping");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 5: LE Data Packet Length Extension");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 6: LL Privacy");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 7: Extended Scanner Filter Policies");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 8: LE 2M PHY");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 9: Stable Modulation Index - Transmitter");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 10: Stable Modulation Index - Receiver");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 11: LE Coded PHY");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 12: LE Extended Advertising");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 13: LE Periodic Advertising");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 14: Channel Selection Algorithm 2");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 15: LE Power Class 1");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 16: Minimum Number of Used Channels Procedure");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 17: Connection Supplemental Request");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 18: Connection Supplemental Response");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 19: Connectionless Supplemental Transmitter");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 20: Connectionless Supplemental Receiver");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 21: Antenna Switching During Supplemental Transmission AoD");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 22: Antenna Switching During Supplemental Reception AoA");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 23: Receiving Constant Tone Extensions");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 24: Periodic Advertising Sync Transfer Sender");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 25: Periodic Advertising Sync Transfer Recipient");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 26: Sleep Clock Accuracy Updates");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 27: Remote Public Key Validation");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 28: Connected Isochronous Stream Master");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 29: Connected Isochronous Stream Slave");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 30: Isochronous Broadcaster");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 31: Synchronized Receiver");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 32: Isochronous Channels Host Support");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 33: LE Power Control Request");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 34: LE Power Change Indication");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 35: LE Path Loss Monitoring");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bits 63-36: Reserved for Future Use");
		return stringBuilder.ToString();
	}
}
