using System.Text;

namespace QCRPG.TSL.BT.Packets;

public static class LinkPolicySettingsInfo
{
	public static LinkPolicySettingsEnumCollection ValueToLinkPolicySettings(uint value)
	{
		LinkPolicySettingsEnumCollection linkPolicySettingsEnumCollection = new LinkPolicySettingsEnumCollection();
		linkPolicySettingsEnumCollection.EnableRoleSwitch = EnableBitInfo.ValueToEnableBit(value & 1u);
		linkPolicySettingsEnumCollection.EnableHoldMode = EnableBitInfo.ValueToEnableBit((value & 2) >> 1);
		linkPolicySettingsEnumCollection.EnableSniffMode = EnableBitInfo.ValueToEnableBit((value & 4) >> 2);
		linkPolicySettingsEnumCollection.EnableParkState = EnableBitInfo.ValueToEnableBit((value & 8) >> 3);
		return linkPolicySettingsEnumCollection;
	}

	public static uint LinkPolicySettingsToValue(LinkPolicySettingsEnumCollection enumCollection)
	{
		uint num = 0u;
		num |= EnableBitInfo.EnableBitToValue(enumCollection.EnableRoleSwitch);
		num |= EnableBitInfo.EnableBitToValue(enumCollection.EnableHoldMode) << 1;
		num |= EnableBitInfo.EnableBitToValue(enumCollection.EnableSniffMode) << 2;
		return num | (EnableBitInfo.EnableBitToValue(enumCollection.EnableParkState) << 3);
	}

	public static string LinkPolicySettingsToString(LinkPolicySettingsEnumCollection enumCollection)
	{
		string text = "";
		text = text + "Enable Role Switch: " + EnableBitInfo.EnableBitToString(enumCollection.EnableRoleSwitch) + "\r\n";
		text = text + "Enable Hold Mode: " + EnableBitInfo.EnableBitToString(enumCollection.EnableHoldMode) + "\r\n";
		text = text + "Enable Sniff Mode: " + EnableBitInfo.EnableBitToString(enumCollection.EnableSniffMode) + "\r\n";
		text = text + "Enable Park State: " + EnableBitInfo.EnableBitToString(enumCollection.EnableParkState) + "\r\n";
		return text.TrimEnd('\r', '\n');
	}

	public static string LinkPolicySettingsToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("Bit 0: Enable Role Switch");
		stringBuilder.AppendLine("Bit 1: Enable Hold Mode");
		stringBuilder.AppendLine("Bit 2: Enable Sniff Mode");
		stringBuilder.AppendLine("Bit 3: Enable Park State");
		stringBuilder.AppendLine("Bits 15-4: Reserved for future use");
		return stringBuilder.ToString();
	}
}
