using System.Text;

namespace QCRPG.TSL.BT.Packets;

public static class ClockAccuracyInfo
{
	public static ClockAccuracyEnum ValueToClockAccuracy(uint value)
	{
		switch (value)
		{
		case 0u:
			return ClockAccuracyEnum.Is_500_ppm;
		case 1u:
			return ClockAccuracyEnum.Is_250_ppm;
		case 2u:
			return ClockAccuracyEnum.Is_150_ppm;
		case 3u:
			return ClockAccuracyEnum.Is_100_ppm;
		case 4u:
			return ClockAccuracyEnum.Is_75_ppm;
		case 5u:
			return ClockAccuracyEnum.Is_50_ppm;
		case 6u:
			return ClockAccuracyEnum.Is_30_ppm;
		case 7u:
			return ClockAccuracyEnum.Is_20_ppm;
		default:
			if (value >= 8 && value <= 255)
			{
				return ClockAccuracyEnum.RESERVED_FOR_FUTURE_USE;
			}
			return ClockAccuracyEnum.InvalidClockAccuracyValue;
		}
	}

	public static uint ClockAccuracyToValue(ClockAccuracyEnum enumItem)
	{
		return enumItem switch
		{
			ClockAccuracyEnum.Is_500_ppm => 0u, 
			ClockAccuracyEnum.Is_250_ppm => 1u, 
			ClockAccuracyEnum.Is_150_ppm => 2u, 
			ClockAccuracyEnum.Is_100_ppm => 3u, 
			ClockAccuracyEnum.Is_75_ppm => 4u, 
			ClockAccuracyEnum.Is_50_ppm => 5u, 
			ClockAccuracyEnum.Is_30_ppm => 6u, 
			ClockAccuracyEnum.Is_20_ppm => 7u, 
			ClockAccuracyEnum.RESERVED_FOR_FUTURE_USE => 8u, 
			_ => uint.MaxValue, 
		};
	}

	public static string ClockAccuracyToString(ClockAccuracyEnum enumItem)
	{
		return enumItem switch
		{
			ClockAccuracyEnum.Is_500_ppm => "500 ppm", 
			ClockAccuracyEnum.Is_250_ppm => "250 ppm", 
			ClockAccuracyEnum.Is_150_ppm => "150 ppm", 
			ClockAccuracyEnum.Is_100_ppm => "100 ppm", 
			ClockAccuracyEnum.Is_75_ppm => "75 ppm", 
			ClockAccuracyEnum.Is_50_ppm => "50 ppm", 
			ClockAccuracyEnum.Is_30_ppm => "30 ppm", 
			ClockAccuracyEnum.Is_20_ppm => "20 ppm", 
			ClockAccuracyEnum.RESERVED_FOR_FUTURE_USE => "Reserved for future use", 
			_ => "Invalid ClockAccuracy Value", 
		};
	}

	public static string ClockAccuracyToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x0 = 500 ppm");
		stringBuilder.AppendLine("0x1 = 250 ppm");
		stringBuilder.AppendLine("0x2 = 150 ppm");
		stringBuilder.AppendLine("0x3 = 100 ppm");
		stringBuilder.AppendLine("0x4 = 75 ppm");
		stringBuilder.AppendLine("0x5 = 50 ppm");
		stringBuilder.AppendLine("0x6 = 30 ppm");
		stringBuilder.AppendLine("0x7 = 20 ppm");
		stringBuilder.AppendLine("0x8-0xFF = Reserved for future use");
		return stringBuilder.ToString();
	}
}
