using System.Text;

namespace QCRPG.TSL.NFC.Packets;

public static class StatusCodesInfo
{
	public static StatusCodesEnum ValueToStatusCodes(uint value)
	{
		switch (value)
		{
		case 0u:
			return StatusCodesEnum.STATUS_OK;
		case 1u:
			return StatusCodesEnum.STATUS_REJECTED;
		case 2u:
			return StatusCodesEnum.STATUS_RF_FRAME_CORRUPTED;
		case 3u:
			return StatusCodesEnum.STATUS_FAILED;
		case 4u:
			return StatusCodesEnum.STATUS_NOT_INITIALIZED;
		case 5u:
			return StatusCodesEnum.STATUS_SYNTAX_ERROR;
		case 6u:
			return StatusCodesEnum.STATUS_SEMANTIC_ERROR;
		case 7u:
			return StatusCodesEnum.STATUS_UNKNOWN_GID;
		case 8u:
			return StatusCodesEnum.STATUS_UNKNOWN_OID;
		case 9u:
			return StatusCodesEnum.STATUS_INVALID_PARAM;
		case 10u:
			return StatusCodesEnum.STATUS_MESSAGE_SIZE_EXCEEDED;
		default:
			if (value >= 11 && value <= 159)
			{
				return StatusCodesEnum.RFU;
			}
			switch (value)
			{
			case 160u:
				return StatusCodesEnum.DISCOVERY_ALREADY_STARTED;
			case 161u:
				return StatusCodesEnum.DISCOVERY_TARGET_ACTIVATION_FAILED;
			case 162u:
				return StatusCodesEnum.DISCOVERY_TEAR_DOWN;
			case 163u:
			case 164u:
			case 165u:
			case 166u:
			case 167u:
			case 168u:
			case 169u:
			case 170u:
			case 171u:
			case 172u:
			case 173u:
			case 174u:
			case 175u:
				return StatusCodesEnum.RFU;
			default:
				switch (value)
				{
				case 176u:
					return StatusCodesEnum.RF_TRANSMISSION_ERROR;
				case 177u:
					return StatusCodesEnum.RF_PROTOCOL_ERROR;
				case 178u:
					return StatusCodesEnum.RF_TIMEOUT_ERROR;
				case 179u:
				case 180u:
				case 181u:
				case 182u:
				case 183u:
				case 184u:
				case 185u:
				case 186u:
				case 187u:
				case 188u:
				case 189u:
				case 190u:
				case 191u:
					return StatusCodesEnum.RFU;
				default:
					switch (value)
					{
					case 192u:
						return StatusCodesEnum.NFCEE_INTERFACE_ACTIVATION_FAILED;
					case 193u:
						return StatusCodesEnum.NFCEE_TRANSMISSION_ERROR;
					case 194u:
						return StatusCodesEnum.NFCEE_PROTOCOL_ERROR;
					case 195u:
						return StatusCodesEnum.NFCEE_TIMEOUT_ERROR;
					case 196u:
					case 197u:
					case 198u:
					case 199u:
					case 200u:
					case 201u:
					case 202u:
					case 203u:
					case 204u:
					case 205u:
					case 206u:
					case 207u:
					case 208u:
					case 209u:
					case 210u:
					case 211u:
					case 212u:
					case 213u:
					case 214u:
					case 215u:
					case 216u:
					case 217u:
					case 218u:
					case 219u:
					case 220u:
					case 221u:
					case 222u:
					case 223u:
						return StatusCodesEnum.RFU;
					default:
						return StatusCodesEnum.InvalidStatusCodesValue;
					}
				}
			}
		}
	}

	public static uint StatusCodesToValue(StatusCodesEnum enumItem)
	{
		switch (enumItem)
		{
		case StatusCodesEnum.STATUS_OK:
			return 0u;
		case StatusCodesEnum.STATUS_REJECTED:
			return 1u;
		case StatusCodesEnum.STATUS_RF_FRAME_CORRUPTED:
			return 2u;
		case StatusCodesEnum.STATUS_FAILED:
			return 3u;
		case StatusCodesEnum.STATUS_NOT_INITIALIZED:
			return 4u;
		case StatusCodesEnum.STATUS_SYNTAX_ERROR:
			return 5u;
		case StatusCodesEnum.STATUS_SEMANTIC_ERROR:
			return 6u;
		case StatusCodesEnum.STATUS_UNKNOWN_GID:
			return 7u;
		case StatusCodesEnum.STATUS_UNKNOWN_OID:
			return 8u;
		case StatusCodesEnum.STATUS_INVALID_PARAM:
			return 9u;
		case StatusCodesEnum.STATUS_MESSAGE_SIZE_EXCEEDED:
			return 10u;
		case StatusCodesEnum.RFU:
			return 11u;
		case StatusCodesEnum.DISCOVERY_ALREADY_STARTED:
			return 160u;
		case StatusCodesEnum.DISCOVERY_TARGET_ACTIVATION_FAILED:
			return 161u;
		case StatusCodesEnum.DISCOVERY_TEAR_DOWN:
			return 162u;
		default:
			switch (enumItem)
			{
			case StatusCodesEnum.RFU:
				return 163u;
			case StatusCodesEnum.RF_TRANSMISSION_ERROR:
				return 176u;
			case StatusCodesEnum.RF_PROTOCOL_ERROR:
				return 177u;
			case StatusCodesEnum.RF_TIMEOUT_ERROR:
				return 178u;
			default:
				switch (enumItem)
				{
				case StatusCodesEnum.RFU:
					return 179u;
				case StatusCodesEnum.NFCEE_INTERFACE_ACTIVATION_FAILED:
					return 192u;
				case StatusCodesEnum.NFCEE_TRANSMISSION_ERROR:
					return 193u;
				case StatusCodesEnum.NFCEE_PROTOCOL_ERROR:
					return 194u;
				case StatusCodesEnum.NFCEE_TIMEOUT_ERROR:
					return 195u;
				default:
					if (enumItem == StatusCodesEnum.RFU)
					{
						return 196u;
					}
					return uint.MaxValue;
				}
			}
		}
	}

	public static string StatusCodesToString(StatusCodesEnum enumItem)
	{
		switch (enumItem)
		{
		case StatusCodesEnum.STATUS_OK:
			return "STATUS_OK";
		case StatusCodesEnum.STATUS_REJECTED:
			return "STATUS_REJECTED";
		case StatusCodesEnum.STATUS_RF_FRAME_CORRUPTED:
			return "STATUS_RF_FRAME_CORRUPTED";
		case StatusCodesEnum.STATUS_FAILED:
			return "STATUS_FAILED";
		case StatusCodesEnum.STATUS_NOT_INITIALIZED:
			return "STATUS_NOT_INITIALIZED";
		case StatusCodesEnum.STATUS_SYNTAX_ERROR:
			return "STATUS_SYNTAX_ERROR";
		case StatusCodesEnum.STATUS_SEMANTIC_ERROR:
			return "STATUS_SEMANTIC_ERROR";
		case StatusCodesEnum.STATUS_UNKNOWN_GID:
			return "STATUS_UNKNOWN_GID";
		case StatusCodesEnum.STATUS_UNKNOWN_OID:
			return "STATUS_UNKNOWN_OID";
		case StatusCodesEnum.STATUS_INVALID_PARAM:
			return "STATUS_INVALID_PARAM";
		case StatusCodesEnum.STATUS_MESSAGE_SIZE_EXCEEDED:
			return "STATUS_MESSAGE_SIZE_EXCEEDED";
		case StatusCodesEnum.RFU:
			return "RFU";
		case StatusCodesEnum.DISCOVERY_ALREADY_STARTED:
			return "DISCOVERY_ALREADY_STARTED";
		case StatusCodesEnum.DISCOVERY_TARGET_ACTIVATION_FAILED:
			return "DISCOVERY_TARGET_ACTIVATION_FAILED";
		case StatusCodesEnum.DISCOVERY_TEAR_DOWN:
			return "DISCOVERY_TEAR_DOWN";
		default:
			switch (enumItem)
			{
			case StatusCodesEnum.RFU:
				return "RFU";
			case StatusCodesEnum.RF_TRANSMISSION_ERROR:
				return "RF_TRANSMISSION_ERROR";
			case StatusCodesEnum.RF_PROTOCOL_ERROR:
				return "RF_PROTOCOL_ERROR";
			case StatusCodesEnum.RF_TIMEOUT_ERROR:
				return "RF_TIMEOUT_ERROR";
			default:
				switch (enumItem)
				{
				case StatusCodesEnum.RFU:
					return "RFU";
				case StatusCodesEnum.NFCEE_INTERFACE_ACTIVATION_FAILED:
					return "NFCEE_INTERFACE_ACTIVATION_FAILED";
				case StatusCodesEnum.NFCEE_TRANSMISSION_ERROR:
					return "NFCEE_TRANSMISSION_ERROR";
				case StatusCodesEnum.NFCEE_PROTOCOL_ERROR:
					return "NFCEE_PROTOCOL_ERROR";
				case StatusCodesEnum.NFCEE_TIMEOUT_ERROR:
					return "NFCEE_TIMEOUT_ERROR";
				default:
					if (enumItem == StatusCodesEnum.RFU)
					{
						return "RFU";
					}
					return "Invalid StatusCodes Value";
				}
			}
		}
	}

	public static string StatusCodesToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x0 = STATUS_OK");
		stringBuilder.AppendLine("0x1 = STATUS_REJECTED");
		stringBuilder.AppendLine("0x2 = STATUS_RF_FRAME_CORRUPTED");
		stringBuilder.AppendLine("0x3 = STATUS_FAILED");
		stringBuilder.AppendLine("0x4 = STATUS_NOT_INITIALIZED");
		stringBuilder.AppendLine("0x5 = STATUS_SYNTAX_ERROR");
		stringBuilder.AppendLine("0x6 = STATUS_SEMANTIC_ERROR");
		stringBuilder.AppendLine("0x7 = STATUS_UNKNOWN_GID");
		stringBuilder.AppendLine("0x8 = STATUS_UNKNOWN_OID");
		stringBuilder.AppendLine("0x9 = STATUS_INVALID_PARAM");
		stringBuilder.AppendLine("0xA = STATUS_MESSAGE_SIZE_EXCEEDED");
		stringBuilder.AppendLine("0xB-0x9F = RFU");
		stringBuilder.AppendLine("0xA0 = DISCOVERY_ALREADY_STARTED");
		stringBuilder.AppendLine("0xA1 = DISCOVERY_TARGET_ACTIVATION_FAILED");
		stringBuilder.AppendLine("0xA2 = DISCOVERY_TEAR_DOWN");
		stringBuilder.AppendLine("0xA3-0xAF = RFU");
		stringBuilder.AppendLine("0xB0 = RF_TRANSMISSION_ERROR");
		stringBuilder.AppendLine("0xB1 = RF_PROTOCOL_ERROR");
		stringBuilder.AppendLine("0xB2 = RF_TIMEOUT_ERROR");
		stringBuilder.AppendLine("0xB3-0xBF = RFU");
		stringBuilder.AppendLine("0xC0 = NFCEE_INTERFACE_ACTIVATION_FAILED");
		stringBuilder.AppendLine("0xC1 = NFCEE_TRANSMISSION_ERROR");
		stringBuilder.AppendLine("0xC2 = NFCEE_PROTOCOL_ERROR");
		stringBuilder.AppendLine("0xC3 = NFCEE_TIMEOUT_ERROR");
		stringBuilder.AppendLine("0xC4-0xDF = RFU");
		return stringBuilder.ToString();
	}
}
