using System.Text;

namespace QCRPG.TSL.NFC.Packets;

public static class BitRatesInfo
{
	public static BitRatesEnum ValueToBitRates(uint value)
	{
		switch (value)
		{
		case 0u:
			return BitRatesEnum.NFC_BIT_RATE_106;
		case 1u:
			return BitRatesEnum.NFC_BIT_RATE_212;
		case 2u:
			return BitRatesEnum.NFC_BIT_RATE_424;
		case 3u:
			return BitRatesEnum.NFC_BIT_RATE_848;
		case 4u:
			return BitRatesEnum.NFC_BIT_RATE_1695;
		case 5u:
			return BitRatesEnum.NFC_BIT_RATE_3390;
		case 6u:
			return BitRatesEnum.NFC_BIT_RATE_6780;
		default:
			if (value >= 7 && value <= 127)
			{
				return BitRatesEnum.RFU;
			}
			if (value >= 128 && value <= 254)
			{
				return BitRatesEnum.PROPRIETARY;
			}
			if (value == 255)
			{
				return BitRatesEnum.RFU;
			}
			return BitRatesEnum.InvalidBitRatesValue;
		}
	}

	public static uint BitRatesToValue(BitRatesEnum enumItem)
	{
		switch (enumItem)
		{
		case BitRatesEnum.NFC_BIT_RATE_106:
			return 0u;
		case BitRatesEnum.NFC_BIT_RATE_212:
			return 1u;
		case BitRatesEnum.NFC_BIT_RATE_424:
			return 2u;
		case BitRatesEnum.NFC_BIT_RATE_848:
			return 3u;
		case BitRatesEnum.NFC_BIT_RATE_1695:
			return 4u;
		case BitRatesEnum.NFC_BIT_RATE_3390:
			return 5u;
		case BitRatesEnum.NFC_BIT_RATE_6780:
			return 6u;
		case BitRatesEnum.RFU:
			return 7u;
		case BitRatesEnum.PROPRIETARY:
			return 128u;
		default:
			if (enumItem == BitRatesEnum.RFU)
			{
				return 255u;
			}
			return uint.MaxValue;
		}
	}

	public static string BitRatesToString(BitRatesEnum enumItem)
	{
		switch (enumItem)
		{
		case BitRatesEnum.NFC_BIT_RATE_106:
			return "NFC_BIT_RATE_106";
		case BitRatesEnum.NFC_BIT_RATE_212:
			return "NFC_BIT_RATE_212";
		case BitRatesEnum.NFC_BIT_RATE_424:
			return "NFC_BIT_RATE_424";
		case BitRatesEnum.NFC_BIT_RATE_848:
			return "NFC_BIT_RATE_848";
		case BitRatesEnum.NFC_BIT_RATE_1695:
			return "NFC_BIT_RATE_1695";
		case BitRatesEnum.NFC_BIT_RATE_3390:
			return "NFC_BIT_RATE_3390";
		case BitRatesEnum.NFC_BIT_RATE_6780:
			return "NFC_BIT_RATE_6780";
		case BitRatesEnum.RFU:
			return "RFU";
		case BitRatesEnum.PROPRIETARY:
			return "PROPRIETARY";
		default:
			if (enumItem == BitRatesEnum.RFU)
			{
				return "RFU";
			}
			return "Invalid BitRates Value";
		}
	}

	public static string BitRatesToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x0 = NFC_BIT_RATE_106");
		stringBuilder.AppendLine("0x1 = NFC_BIT_RATE_212");
		stringBuilder.AppendLine("0x2 = NFC_BIT_RATE_424");
		stringBuilder.AppendLine("0x3 = NFC_BIT_RATE_848");
		stringBuilder.AppendLine("0x4 = NFC_BIT_RATE_1695");
		stringBuilder.AppendLine("0x5 = NFC_BIT_RATE_3390");
		stringBuilder.AppendLine("0x6 = NFC_BIT_RATE_6780");
		stringBuilder.AppendLine("0x7-0x7F = RFU");
		stringBuilder.AppendLine("0x80-0xFE = PROPRIETARY");
		stringBuilder.AppendLine("0xFF = RFU");
		return stringBuilder.ToString();
	}
}
