package eu.europa.esig.dss.validation;

import java.util.HashMap;
import java.util.Map;

public enum CertificateQualification {

	/**
	 * Qualified Certificate for Electronic Signatures with private key on QSCD
	 */
	QCERT_FOR_ESIG_QSCD("QC Cert for ESig with QSCD", "Qualified Certificate for Electronic Signatures with private key on QSCD", true, true, true),

	/**
	 * Qualified Certificate for Electronic Seals with private key on QSCD
	 */
	QCERT_FOR_ESEAL_QSCD("QC Cert for ESeal with QSCD", "Qualified Certificate for Electronic Seals with private key on QSCD", true, false, true),

	// QCERT_FOR_WSA_QSCD non sense

	// --------------------------------------------------------

	/**
	 * Qualified Certificate for Electronic Signatures
	 */
	QCERT_FOR_ESIG("QC Cert for ESig", "Qualified Certificate for Electronic Signatures", true, true, false),

	/**
	 * Qualified Certificate for Electronic Seals
	 */
	QCERT_FOR_ESEAL("QC Cert for ESeal", "Qualified Certificate for Electronic Seals", true, false, false),

	/**
	 * Qualified Certificate for Web Site Authentications
	 */
	QCERT_FOR_WSA("QC Cert for WSA", "Qualified Certificate for Web Site Authentications", true, false, false),

	// --------------------------------------------------------

	/**
	 * Certificate for Electronic Signatures
	 */
	CERT_FOR_ESIG("Cert for ESig", "Certificate for Electronic Signatures", false, true, false),

	/**
	 * Certificate for Electronic Seals
	 */
	CERT_FOR_ESEAL("Cert for ESeal", "Certificate for Electronic Seals", false, false, false),

	/**
	 * Certificate for Web Site Authentications
	 */
	CERT_FOR_WSA("Cert for WSA", "Certificate for Web Site Authentications", false, false, false),

	/**
	 * Not Applicable
	 */
	NA("N/A", "Not applicable", false, false, false);

	private static class Registry {

		private final static Map<String, CertificateQualification> QUALIFS_BY_READABLE = registerByReadable();

		private static Map<String, CertificateQualification> registerByReadable() {
			final Map<String, CertificateQualification> map = new HashMap<String, CertificateQualification>();
			for (final CertificateQualification qualification : values()) {
				map.put(qualification.readable, qualification);
			}
			return map;
		}
	}

	private final String readable;
	private final String label;
	private final boolean qc;
	private final boolean forEsig;
	private final boolean qscd;

	private CertificateQualification(String readable, String label, boolean qc, boolean forEsig, boolean qscd) {
		this.readable = readable;
		this.label = label;
		this.qc = qc;
		this.forEsig = forEsig;
		this.qscd = qscd;
	}

	public String getReadable() {
		return readable;
	}

	public String getLabel() {
		return label;
	}

	/**
	 * CertificateQualification can be null
	 * 
	 * @param value
	 *            the qualification name to be converted to the enum
	 * @return the linked CertificateQualification or null
	 */
	public static CertificateQualification forName(String value) {
		if ((value != null) && !value.isEmpty()) {
			return CertificateQualification.valueOf(value);
		}
		return null;
	}

	/**
	 * CertificateQualification can be null
	 * 
	 * @param readable
	 *            the readable description of the qualification to be converted to the enum
	 * @return the linked CertificateQualification or null
	 */
	public static CertificateQualification fromReadable(String readable) {
		if ((readable != null) && !readable.isEmpty()) {
			return Registry.QUALIFS_BY_READABLE.get(readable);
		}
		return null;
	}

	public boolean isQc() {
		return qc;
	}

	public boolean isForEsig() {
		return forEsig;
	}

	public boolean isQscd() {
		return qscd;
	}

}

@@ -234,26 +234,21 @@
 SCD(%22QC 
-Cert 
 for 
-E
+e
 Sig with
@@ -246,33 +246,36 @@
 eSig with QSCD%22,
- 
+%0A%09%09%09
 %22Qualified Certi
@@ -458,34 +458,29 @@
 AL_QSCD(%22QC 
-Cert 
 for 
-E
+e
 Seal with QS
@@ -483,17 +483,20 @@
 h QSCD%22,
- 
+%0A%09%09%09
 %22Qualifi
@@ -757,26 +757,21 @@
 SIG(%22QC 
-Cert 
 for 
-E
+e
 Sig%22, %22Q
@@ -918,26 +918,21 @@
 EAL(%22QC 
-Cert 
 for 
-E
+e
 Seal%22, %22
@@ -1082,21 +1082,16 @@
 WSA(%22QC 
-Cert 
 for WSA%22
@@ -1307,17 +1307,17 @@
 ert for 
-E
+e
 Sig%22, %22C
@@ -1450,17 +1450,17 @@
 ert for 
-E
+e
 Seal%22, %22

Improve labels