package com.capgemini.reports.database.javabean.enumeration;

import com.capgemini.reports.database.javabean.DbCriteria;
import com.capgemini.reports.database.javabean.DbSchedulingCriteriaVal;

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


/** List of criteria values. Any change made to this class must be mirrored in the installation script of the database. **/
public enum ReportCriteriaEnum {

    /**
     * TcEffectivity date.
     */
    EFFECTIVITY_DATE("Date d'effectivité"),
    /** Generic ID. */
    GENERIC("Générique"),
    /** Generic Assemb ID. */
    GENERIC_ASSEMB("Générique montage"),
    /** Nomenclature explosion level (MONO/MULTI). */
    MONO_MULTI("Niveau"),
    /** Part ID. */
    PART_ID("Numéro d'article"),
    /** Revision of the item. */
    PART_REVISION("Révision"),
    /** Document ID. */
    DOCUMENT_ID("Numéro document"),
    /** Revision of the document. */
    DOCUMENT_REVISION("Document Révision"),
    /** Product ID. */
    PRODUCT("Produit"),
    /** Unit number. */
    UNIT("Unit"),
    /** Unit before. */
    UNIT_BEFORE("Unit précédent"),
    /** unit after. */
    UNIT_AFTER("Unit suivant"),
    /** Product before. */
    PRODUCT_BEFORE("Produit précédent"),
    /** Product after. */
    PRODUCT_AFTER("Produit suivant"),
    /** Engine number. */
    MATRICULE("Matricule moteur"),
    /** List of removed modifications. */
    LMR("LMR"),
    /** Class. */
    CLASSE("Classe"),
    /** Major/Minor. */
    MAJOR_MINOR("Majeur mineur"),
    /** Conjoint/Unique. */
    CONJOINT_UNIQUE("Conjoint unique"),
    /** Language. */
    LANGUAGE("Langue"),
    /** Print type. */
    TYPE_IMPRESSION("Type d'impression"),
    /** Start date. */
    DATE_DEBUT("Date de début"),
    /** End date. */
    DATE_FIN("Date de fin"),
    /** Object type. */
    TYPE_OBJET("Type d'objet"),
    /** Unit number in configuration 1. */
    UNIT_CONFIGURATION_1("Unit configuration 1"),
    /** Unit number in configuration 2. */
    UNIT_CONFIGURATION_2("Unit configuration 2"),
    /** Règle de révision. */
    REVISION_RULE("Règle de révision"),
    /** Item */
    ITEM("Item"),
    /** Supermodel */
    SUPERMODEL("SuperModel"),
    /** Avec le(s) unit(s) gelé(s) */
    WITH_FROZEN_UNIT("Avec le(s) unit(s) gelé(s)"),
    /** A partir de Unit */
    FROM_UNIT("A partir de Unit"),
    /** Units gelés il y a moins de */
    UNITS_FROZEN_SINCE_LESS_THAN("Units gelés il y a moins de");

    /** Human readable value for the enumeration. **/
    private final String criteriaValue;

    /** Enumeration cache for conversions. **/
    private static Map<String, ReportCriteriaEnum> enumMap;

    /** Enumeration constructor. **/
    ReportCriteriaEnum(final String aCriteriaValue) {
        criteriaValue = aCriteriaValue;
    }

    /**
     * Getter for object string value.
     * 
     * @return String value with readable format
     **/
    @Override
    public String toString() {
        return criteriaValue;
    }

    /**
     * Conversion from String to SnecmaObjectTypeEnum.
     * 
     * @param aCriteriaValue String value of the criteria
     * @return Enumeration instance for the requested value
     **/
    public static synchronized ReportCriteriaEnum getEnum(final String aCriteriaValue) {
        if (enumMap == null) {
            enumMap = new HashMap<>();
            for (ReportCriteriaEnum currentEnum : ReportCriteriaEnum.values()) {
                enumMap.put(currentEnum.toString(), currentEnum);
            }
        }
        return enumMap.get(aCriteriaValue);
    }

    /**
     * Conversion from {@link DbSchedulingCriteriaVal} to {@link ReportCriteriaEnum}. Uses the enum's criteriaValue property for string matching.
     * 
     * @param criteria String value of the criteria
     * @return Enumeration instance for the requested value
     **/
    public static synchronized ReportCriteriaEnum valueOf(final DbSchedulingCriteriaVal criteria) {
        return getEnum(criteria.getDbCriteria().getCriteriaName());
    }

    /**
     * Conversion from {@link DbCriteria} to {@link ReportCriteriaEnum}. Uses the enum's criteriaValue property for string matching.
     * 
     * @param criteria a {@link DbCriteria}
     * @return Enumeration instance for the requested value
     **/
    public static synchronized ReportCriteriaEnum valueOf(final DbCriteria criteria) {
        return getEnum(criteria.getCriteriaName());
    }
}
