using System.Text;

namespace QCRPG.TSL.NFC.Packets;

public static class RfInterfacesInfo
{
	public static RfInterfacesEnum ValueToRfInterfaces(uint value)
	{
		switch (value)
		{
		case 0u:
			return RfInterfacesEnum.NFCEE_DIRECT_RF_INTERFACE;
		case 1u:
			return RfInterfacesEnum.FRAME_RF_INTERFACE;
		case 2u:
			return RfInterfacesEnum.ISO_DEP_RF_INTERFACE;
		case 3u:
			return RfInterfacesEnum.NFC_DEP_RF_INTERFACE;
		default:
			if (value >= 4 && value <= 127)
			{
				return RfInterfacesEnum.RFU;
			}
			if (value >= 128 && value <= 254)
			{
				return RfInterfacesEnum.PROPRIETARY;
			}
			if (value == 255)
			{
				return RfInterfacesEnum.RFU;
			}
			return RfInterfacesEnum.InvalidRfInterfacesValue;
		}
	}

	public static uint RfInterfacesToValue(RfInterfacesEnum enumItem)
	{
		switch (enumItem)
		{
		case RfInterfacesEnum.NFCEE_DIRECT_RF_INTERFACE:
			return 0u;
		case RfInterfacesEnum.FRAME_RF_INTERFACE:
			return 1u;
		case RfInterfacesEnum.ISO_DEP_RF_INTERFACE:
			return 2u;
		case RfInterfacesEnum.NFC_DEP_RF_INTERFACE:
			return 3u;
		case RfInterfacesEnum.RFU:
			return 4u;
		case RfInterfacesEnum.PROPRIETARY:
			return 128u;
		default:
			if (enumItem == RfInterfacesEnum.RFU)
			{
				return 255u;
			}
			return uint.MaxValue;
		}
	}

	public static string RfInterfacesToString(RfInterfacesEnum enumItem)
	{
		switch (enumItem)
		{
		case RfInterfacesEnum.NFCEE_DIRECT_RF_INTERFACE:
			return "NFCEE_DIRECT_RF_INTERFACE";
		case RfInterfacesEnum.FRAME_RF_INTERFACE:
			return "FRAME_RF_INTERFACE";
		case RfInterfacesEnum.ISO_DEP_RF_INTERFACE:
			return "ISO_DEP_RF_INTERFACE";
		case RfInterfacesEnum.NFC_DEP_RF_INTERFACE:
			return "NFC_DEP_RF_INTERFACE";
		case RfInterfacesEnum.RFU:
			return "RFU";
		case RfInterfacesEnum.PROPRIETARY:
			return "PROPRIETARY";
		default:
			if (enumItem == RfInterfacesEnum.RFU)
			{
				return "RFU";
			}
			return "Invalid RfInterfaces Value";
		}
	}

	public static string RfInterfacesToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x0 = NFCEE_DIRECT_RF_INTERFACE");
		stringBuilder.AppendLine("0x1 = FRAME_RF_INTERFACE");
		stringBuilder.AppendLine("0x2 = ISO_DEP_RF_INTERFACE");
		stringBuilder.AppendLine("0x3 = NFC_DEP_RF_INTERFACE");
		stringBuilder.AppendLine("0x4-0x7F = RFU");
		stringBuilder.AppendLine("0x80-0xFE = PROPRIETARY");
		stringBuilder.AppendLine("0xFF = RFU");
		return stringBuilder.ToString();
	}
}
