package com.capgemini.reports;

import com.capgemini.framework.common.SettingsHelper;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/** Enumeration of the different launch type of a report. */
@Slf4j
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum ReportLaunchTypeEnum {

    /** The immediate launch type. */
    IMMEDIATE("immediate", "none"),
    /** The delayed launch type. */
    DELAYED("delayed", "delayed"),
    /** The scheduled launch type. */
    SCHEDULED("scheduled", "scheduled"),
    /** The scheduled launch type. */
    AUTOMATIC("automatic", "immediate");

    private final String launchType;
    private final String groupName;

    private static final String DEFAULT_LAUNCH_TYPE = SettingsHelper.getDefaultLaunchType();

    /**
     * Give the appropriate {@link ReportLaunchTypeEnum} associate to the string value.<br/>
     * Else return null.
     * 
     * @param personnalizeValueIfExist String - the string value
     * @return the appropriate {@link ReportLaunchTypeEnum}. Return null if the string value doesn't exist.
     */
    public static ReportLaunchTypeEnum getReportLaunchType(final String personnalizeValueIfExist) {
        // Determine the string value of the type
        String realValue = SettingsHelper.getPropertyWithDefaultValue(personnalizeValueIfExist, DEFAULT_LAUNCH_TYPE);

        // Determine the enumeration value
        ReportLaunchTypeEnum launchType;
        if ("immediate".equals(realValue)) {
            launchType = ReportLaunchTypeEnum.IMMEDIATE;
        } else if ("delayed".equals(realValue)) {
            launchType = ReportLaunchTypeEnum.DELAYED;
        } else if ("scheduled".equals(realValue)) {
            launchType = ReportLaunchTypeEnum.SCHEDULED;
        } else if ("automatic".equals(realValue)) {
            launchType = ReportLaunchTypeEnum.AUTOMATIC;
        } else {
            log.error("No status found. The string {} is not valid.", realValue);
            launchType = null;
        }
        return launchType;
    }
}
