using System.Text;

namespace QCRPG.TSL.BT.Packets;

public static class ExtendedFeaturesPage2Info
{
	public static ExtendedFeaturesPage2EnumCollection ValueToExtendedFeaturesPage2(ulong value)
	{
		ExtendedFeaturesPage2EnumCollection extendedFeaturesPage2EnumCollection = new ExtendedFeaturesPage2EnumCollection();
		extendedFeaturesPage2EnumCollection.ConnectionlessSlaveBroadcastMasterOperation = SupportBitInfo.ValueToSupportBit((uint)(value & 1));
		extendedFeaturesPage2EnumCollection.ConnectionlessSlaveBroadcastSlaveOperation = SupportBitInfo.ValueToSupportBit((uint)((value & 2) >> 1));
		extendedFeaturesPage2EnumCollection.SynchronizationTrain = SupportBitInfo.ValueToSupportBit((uint)((value & 4) >> 2));
		extendedFeaturesPage2EnumCollection.SynchronizationScan = SupportBitInfo.ValueToSupportBit((uint)((value & 8) >> 3));
		extendedFeaturesPage2EnumCollection.InquiryResponseNotificationEvent = SupportBitInfo.ValueToSupportBit((uint)((value & 0x10) >> 4));
		extendedFeaturesPage2EnumCollection.GeneralizedInterlacedScan = SupportBitInfo.ValueToSupportBit((uint)((value & 0x20) >> 5));
		extendedFeaturesPage2EnumCollection.CoarseClockAdjustment = SupportBitInfo.ValueToSupportBit((uint)((value & 0x40) >> 6));
		extendedFeaturesPage2EnumCollection.SecureConnectionsControllerSupport = SupportBitInfo.ValueToSupportBit((uint)((value & 0x100) >> 8));
		extendedFeaturesPage2EnumCollection.Ping = SupportBitInfo.ValueToSupportBit((uint)((value & 0x200) >> 9));
		extendedFeaturesPage2EnumCollection.TrainNudging = SupportBitInfo.ValueToSupportBit((uint)((value & 0x800) >> 11));
		return extendedFeaturesPage2EnumCollection;
	}

	public static ulong ExtendedFeaturesPage2ToValue(ExtendedFeaturesPage2EnumCollection enumCollection)
	{
		ulong num = 0uL;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.ConnectionlessSlaveBroadcastMasterOperation);
		num |= SupportBitInfo.SupportBitToValue(enumCollection.ConnectionlessSlaveBroadcastSlaveOperation) << 1;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.SynchronizationTrain) << 2;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.SynchronizationScan) << 3;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.InquiryResponseNotificationEvent) << 4;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.GeneralizedInterlacedScan) << 5;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.CoarseClockAdjustment) << 6;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.SecureConnectionsControllerSupport) << 8;
		num |= SupportBitInfo.SupportBitToValue(enumCollection.Ping) << 9;
		return num | (SupportBitInfo.SupportBitToValue(enumCollection.TrainNudging) << 11);
	}

	public static string ExtendedFeaturesPage2ToString(ExtendedFeaturesPage2EnumCollection enumCollection)
	{
		string text = "";
		text = text + "Connectionless Slave Broadcast Master Operation: " + SupportBitInfo.SupportBitToString(enumCollection.ConnectionlessSlaveBroadcastMasterOperation) + "\r\n";
		text = text + "Connectionless Slave Broadcast Slave Operation: " + SupportBitInfo.SupportBitToString(enumCollection.ConnectionlessSlaveBroadcastSlaveOperation) + "\r\n";
		text = text + "Synchronization Train: " + SupportBitInfo.SupportBitToString(enumCollection.SynchronizationTrain) + "\r\n";
		text = text + "Synchronization Scan: " + SupportBitInfo.SupportBitToString(enumCollection.SynchronizationScan) + "\r\n";
		text = text + "Inquiry Response Notification Event: " + SupportBitInfo.SupportBitToString(enumCollection.InquiryResponseNotificationEvent) + "\r\n";
		text = text + "Generalized interlaced scan: " + SupportBitInfo.SupportBitToString(enumCollection.GeneralizedInterlacedScan) + "\r\n";
		text = text + "Coarse Clock Adjustment: " + SupportBitInfo.SupportBitToString(enumCollection.CoarseClockAdjustment) + "\r\n";
		text = text + "Secure Connections Controller Support: " + SupportBitInfo.SupportBitToString(enumCollection.SecureConnectionsControllerSupport) + "\r\n";
		text = text + "Ping: " + SupportBitInfo.SupportBitToString(enumCollection.Ping) + "\r\n";
		text = text + "Train nudging: " + SupportBitInfo.SupportBitToString(enumCollection.TrainNudging) + "\r\n";
		return text.TrimEnd('\r', '\n');
	}

	public static string ExtendedFeaturesPage2ToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("Bit 0: Connectionless Slave Broadcast Master Operation");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 1: Connectionless Slave Broadcast Slave Operation");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 2: Synchronization Train");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 3: Synchronization Scan");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 4: Inquiry Response Notification Event");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 5: Generalized interlaced scan");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 6: Coarse Clock Adjustment");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 7: Reserved");
		stringBuilder.AppendLine("Bit 8: Secure Connections Controller Support");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 9: Ping");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		stringBuilder.AppendLine("Bit 10: Reserved");
		stringBuilder.AppendLine("Bit 11: Train nudging");
		stringBuilder.AppendLine(SupportBitInfo.SupportBitToDescription());
		return stringBuilder.ToString();
	}
}
