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

import lombok.AllArgsConstructor;
import lombok.Getter;

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

/** KEYS of CriteriaValue in DB. Please use {@link SchedulingEnum#getEnum(String)} to obtain an instance from its DB value. */
@AllArgsConstructor
@Getter
public enum SchedulingEnum {

    /** Key to the declared periodicity. Values are 'daily', 'weekly', 'weekend', 'date'. */
    PERIOD("period"),
    /** Key to schedule every days (Monday to Sunday). No value required. */
    DAILY("daily"),
    /** Key to schedule once every week (Monday to Friday only). Values available: 1, 2, 3, 4, 5. */
    WEEKLY("weekly"),
    /** Key to schedule a specific day of every month. Values availble: 1, 2, 3... 31, 'we_1', 'we_2', 'we_3', 'we_4', 'we_5', 'we_6' <-- for end of month. */
    WEEKEND("weekend"),
    /** scheduling by date. */
    DATE("date"),
    /** value of month. */
    DAY_IN_MONTH_VALUE("day_in_month_value");

    /** Human readable name for the enumeration. **/
    private final String criteriaName;

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

    static {
        enumMap = new HashMap<>();
        for (SchedulingEnum currentEnum : SchedulingEnum.values()) {
            enumMap.put(currentEnum.toString(), currentEnum);
        }
    }

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

    /**
     * Conversion from String to SchedulingEnum.
     * 
     * @param aSchedulingCriteriaValue String value of the criteria
     * @return Enumeration instance for the requested value
     **/
    public static synchronized SchedulingEnum getEnum(final String aSchedulingCriteriaValue) {
        return enumMap.get(aSchedulingCriteriaValue);
    }
}
