using System.Text;

namespace QCRPG.TSL.FMHCI.Packets;

public static class ErrorCodeInfo
{
	public static ErrorCodeEnum ValueToErrorCode(uint value)
	{
		switch (value)
		{
		case 0u:
			return ErrorCodeEnum.SUCCESS;
		case 1u:
			return ErrorCodeEnum.UNKNOWN_HCI_COMMAND;
		case 2u:
			return ErrorCodeEnum.UNKNOWN_CONNECTION_IDENTIFIER;
		case 3u:
			return ErrorCodeEnum.HARDWARE_FAILURE;
		default:
			if (value >= 4 && value <= 6)
			{
				return ErrorCodeEnum.RESERVED;
			}
			switch (value)
			{
			case 7u:
				return ErrorCodeEnum.MEMORY_CAPACITY_EXCEEDED;
			case 8u:
			case 9u:
			case 10u:
			case 11u:
				return ErrorCodeEnum.RESERVED;
			default:
				switch (value)
				{
				case 12u:
					return ErrorCodeEnum.COMMAND_DISALLOWED;
				case 13u:
				case 14u:
				case 15u:
				case 16u:
					return ErrorCodeEnum.RESERVED;
				default:
					switch (value)
					{
					case 17u:
						return ErrorCodeEnum.UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
					case 18u:
						return ErrorCodeEnum.INVALID_HCI_COMMAND_PARAMETERS;
					case 19u:
					case 20u:
					case 21u:
					case 22u:
					case 23u:
					case 24u:
					case 25u:
					case 26u:
					case 27u:
					case 28u:
					case 29u:
					case 30u:
						return ErrorCodeEnum.RESERVED;
					default:
						switch (value)
						{
						case 31u:
							return ErrorCodeEnum.UNSPECIFIED_ERROR;
						case 32u:
						case 33u:
						case 34u:
						case 35u:
						case 36u:
						case 37u:
						case 38u:
						case 39u:
						case 40u:
						case 41u:
						case 42u:
						case 43u:
						case 44u:
						case 45u:
						case 46u:
						case 47u:
							return ErrorCodeEnum.RESERVED;
						default:
							if (value == 48)
							{
								return ErrorCodeEnum.PARAMETER_OUT_OF_MANDATORY_RANGE;
							}
							if (value >= 49 && value <= 255)
							{
								return ErrorCodeEnum.RESERVED;
							}
							return ErrorCodeEnum.InvalidErrorCodeValue;
						}
					}
				}
			}
		}
	}

	public static uint ErrorCodeToValue(ErrorCodeEnum enumItem)
	{
		switch (enumItem)
		{
		case ErrorCodeEnum.SUCCESS:
			return 0u;
		case ErrorCodeEnum.UNKNOWN_HCI_COMMAND:
			return 1u;
		case ErrorCodeEnum.UNKNOWN_CONNECTION_IDENTIFIER:
			return 2u;
		case ErrorCodeEnum.HARDWARE_FAILURE:
			return 3u;
		case ErrorCodeEnum.RESERVED:
			return 4u;
		case ErrorCodeEnum.MEMORY_CAPACITY_EXCEEDED:
			return 7u;
		default:
			switch (enumItem)
			{
			case ErrorCodeEnum.RESERVED:
				return 8u;
			case ErrorCodeEnum.COMMAND_DISALLOWED:
				return 12u;
			default:
				switch (enumItem)
				{
				case ErrorCodeEnum.RESERVED:
					return 13u;
				case ErrorCodeEnum.UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE:
					return 17u;
				case ErrorCodeEnum.INVALID_HCI_COMMAND_PARAMETERS:
					return 18u;
				default:
					switch (enumItem)
					{
					case ErrorCodeEnum.RESERVED:
						return 19u;
					case ErrorCodeEnum.UNSPECIFIED_ERROR:
						return 31u;
					default:
						switch (enumItem)
						{
						case ErrorCodeEnum.RESERVED:
							return 32u;
						case ErrorCodeEnum.PARAMETER_OUT_OF_MANDATORY_RANGE:
							return 48u;
						default:
							if (enumItem == ErrorCodeEnum.RESERVED)
							{
								return 49u;
							}
							return uint.MaxValue;
						}
					}
				}
			}
		}
	}

	public static string ErrorCodeToString(ErrorCodeEnum enumItem)
	{
		switch (enumItem)
		{
		case ErrorCodeEnum.SUCCESS:
			return "SUCCESS";
		case ErrorCodeEnum.UNKNOWN_HCI_COMMAND:
			return "UNKNOWN_HCI_COMMAND";
		case ErrorCodeEnum.UNKNOWN_CONNECTION_IDENTIFIER:
			return "UNKNOWN_CONNECTION_IDENTIFIER";
		case ErrorCodeEnum.HARDWARE_FAILURE:
			return "HARDWARE_FAILURE";
		case ErrorCodeEnum.RESERVED:
			return "RESERVED";
		case ErrorCodeEnum.MEMORY_CAPACITY_EXCEEDED:
			return "MEMORY_CAPACITY_EXCEEDED";
		default:
			switch (enumItem)
			{
			case ErrorCodeEnum.RESERVED:
				return "RESERVED";
			case ErrorCodeEnum.COMMAND_DISALLOWED:
				return "COMMAND_DISALLOWED";
			default:
				switch (enumItem)
				{
				case ErrorCodeEnum.RESERVED:
					return "RESERVED";
				case ErrorCodeEnum.UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE:
					return "UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE";
				case ErrorCodeEnum.INVALID_HCI_COMMAND_PARAMETERS:
					return "INVALID_HCI_COMMAND_PARAMETERS";
				default:
					switch (enumItem)
					{
					case ErrorCodeEnum.RESERVED:
						return "RESERVED";
					case ErrorCodeEnum.UNSPECIFIED_ERROR:
						return "UNSPECIFIED_ERROR";
					default:
						switch (enumItem)
						{
						case ErrorCodeEnum.RESERVED:
							return "RESERVED";
						case ErrorCodeEnum.PARAMETER_OUT_OF_MANDATORY_RANGE:
							return "PARAMETER_OUT_OF_MANDATORY_RANGE";
						default:
							if (enumItem == ErrorCodeEnum.RESERVED)
							{
								return "RESERVED";
							}
							return "Invalid ErrorCode Value";
						}
					}
				}
			}
		}
	}

	public static string ErrorCodeToDescription()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("0x0 = SUCCESS");
		stringBuilder.AppendLine("0x1 = UNKNOWN_HCI_COMMAND");
		stringBuilder.AppendLine("0x2 = UNKNOWN_CONNECTION_IDENTIFIER");
		stringBuilder.AppendLine("0x3 = HARDWARE_FAILURE");
		stringBuilder.AppendLine("0x4-0x6 = RESERVED");
		stringBuilder.AppendLine("0x7 = MEMORY_CAPACITY_EXCEEDED");
		stringBuilder.AppendLine("0x8-0xB = RESERVED");
		stringBuilder.AppendLine("0xC = COMMAND_DISALLOWED");
		stringBuilder.AppendLine("0xD-0x10 = RESERVED");
		stringBuilder.AppendLine("0x11 = UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE");
		stringBuilder.AppendLine("0x12 = INVALID_HCI_COMMAND_PARAMETERS");
		stringBuilder.AppendLine("0x13-0x1E = RESERVED");
		stringBuilder.AppendLine("0x1F = UNSPECIFIED_ERROR");
		stringBuilder.AppendLine("0x20-0x2F = RESERVED");
		stringBuilder.AppendLine("0x30 = PARAMETER_OUT_OF_MANDATORY_RANGE");
		stringBuilder.AppendLine("0x31-0xFF = RESERVED");
		return stringBuilder.ToString();
	}
}
