using System.Text;

namespace QCRPG.TSL.BT.Packets;

public static class AdvertisingPhyInfo
{
	public static AdvertisingPhyEnum ValueToAdvertisingPhy(uint value)
	{
		switch (value)
		{
		case 0u:
			return AdvertisingPhyEnum.Reserved_for_future_use;
		case 1u:
			return AdvertisingPhyEnum.Advertiser_PHY_is_LE_1M;
		case 2u:
			return AdvertisingPhyEnum.Advertiser_PHY_is_LE_2M;
		case 3u:
			return AdvertisingPhyEnum.Advertiser_PHY_is_LE_Coded;
		default:
			if (value >= 4 && value <= 255)
			{
				return AdvertisingPhyEnum.Reserved_for_future_use;
			}
			return AdvertisingPhyEnum.InvalidAdvertisingPhyValue;
		}
	}

	public static uint AdvertisingPhyToValue(AdvertisingPhyEnum enumItem)
	{
		switch (enumItem)
		{
		case AdvertisingPhyEnum.Reserved_for_future_use:
			return 0u;
		case AdvertisingPhyEnum.Advertiser_PHY_is_LE_1M:
			return 1u;
		case AdvertisingPhyEnum.Advertiser_PHY_is_LE_2M:
			return 2u;
		case AdvertisingPhyEnum.Advertiser_PHY_is_LE_Coded:
			return 3u;
		default:
			if (enumItem == AdvertisingPhyEnum.Reserved_for_future_use)
			{
				return 4u;
			}
			return uint.MaxValue;
		}
	}

	public static string AdvertisingPhyToString(AdvertisingPhyEnum enumItem)
	{
		switch (enumItem)
		{
		case AdvertisingPhyEnum.Reserved_for_future_use:
			return "Reserved for future use";
		case AdvertisingPhyEnum.Advertiser_PHY_is_LE_1M:
			return "Advertiser PHY is LE 1M";
		case AdvertisingPhyEnum.Advertiser_PHY_is_LE_2M:
			return "Advertiser PHY is LE 2M";
		case AdvertisingPhyEnum.Advertiser_PHY_is_LE_Coded:
			return "Advertiser PHY is LE Coded";
		default:
			if (enumItem == AdvertisingPhyEnum.Reserved_for_future_use)
			{
				return "Reserved for future use";
			}
			return "Invalid AdvertisingPhy Value";
		}
	}

	public static string AdvertisingPhyToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x0 = Reserved for future use");
		stringBuilder.AppendLine("0x1 = Advertiser PHY is LE 1M");
		stringBuilder.AppendLine("0x2 = Advertiser PHY is LE 2M");
		stringBuilder.AppendLine("0x3 = Advertiser PHY is LE Coded");
		stringBuilder.AppendLine("0x4-0xFF = Reserved for future use");
		return stringBuilder.ToString();
	}
}
