using System.Text;

namespace QCRPG.TSL.BT.Packets;

public static class FragmentPreferenceInfo
{
	public static FragmentPreferenceEnum ValueToFragmentPreference(uint value)
	{
		switch (value)
		{
		case 0u:
			return FragmentPreferenceEnum.The_Controller_may_fragment_all_Host_advertising_data;
		case 1u:
			return FragmentPreferenceEnum.The_Controller_should_not_fragment_nor_minimize_fragmentation_of_Host_advertising_data;
		default:
			if (value >= 2 && value <= 255)
			{
				return FragmentPreferenceEnum.Reserved_for_future_use;
			}
			return FragmentPreferenceEnum.InvalidFragmentPreferenceValue;
		}
	}

	public static uint FragmentPreferenceToValue(FragmentPreferenceEnum enumItem)
	{
		return enumItem switch
		{
			FragmentPreferenceEnum.The_Controller_may_fragment_all_Host_advertising_data => 0u, 
			FragmentPreferenceEnum.The_Controller_should_not_fragment_nor_minimize_fragmentation_of_Host_advertising_data => 1u, 
			FragmentPreferenceEnum.Reserved_for_future_use => 2u, 
			_ => uint.MaxValue, 
		};
	}

	public static string FragmentPreferenceToString(FragmentPreferenceEnum enumItem)
	{
		return enumItem switch
		{
			FragmentPreferenceEnum.The_Controller_may_fragment_all_Host_advertising_data => "The Controller may fragment all Host advertising data", 
			FragmentPreferenceEnum.The_Controller_should_not_fragment_nor_minimize_fragmentation_of_Host_advertising_data => "The Controller should not fragment nor minimize fragmentation of Host advertising data", 
			FragmentPreferenceEnum.Reserved_for_future_use => "Reserved for future use", 
			_ => "Invalid FragmentPreference Value", 
		};
	}

	public static string FragmentPreferenceToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x0 = The Controller may fragment all Host advertising data");
		stringBuilder.AppendLine("0x1 = The Controller should not fragment nor minimize fragmentation of Host advertising data");
		stringBuilder.AppendLine("0x2-0xFF = Reserved for future use");
		return stringBuilder.ToString();
	}
}
