package com.capgemini.reports.queuing;

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

/** Reflects the priority level of each report. */
@Getter
@Slf4j
public enum ReportPriority {
    HIGH_PRIORITY(1),
    MED_PRIORITY(2),
    LOW_PRIORITY(3);

    private static final int HIGH_PRIORITY_VALUE = 1;
    private static final int MED_PRIORITY_VALUE = 2;
    private static final int LOW_PRIORITY_VALUE = 3;

    private final int priorityValue;

    ReportPriority(final int priorityValue) {
        this.priorityValue = priorityValue;
    }

    @Override
    public String toString() {
        String val;
        switch (this) {
            case HIGH_PRIORITY:
                val = "High Priority Queue";
                break;
            case MED_PRIORITY:
                val = "Medium Priority Queue";
                break;
            case LOW_PRIORITY:
                val = "Low Priority Queue";
                break;
            default:
                val = "No Queue";
                break;
        }
        return val;
    }

    /**
     * Give the appropriate {@link ReportPriority} associate to a code:<br/>
     * <ul>
     * <li>Code 1 : HIGH_PRIORITY</li>
     * <li>Code 2 : MED_PRIORITY</li>
     * <li>Code 3 : LOW_PRIORITY</li>
     * </ul>
     * Else return null.
     * 
     * @param value int - the code value
     * @return the appropriate {@link ReportPriority}
     */
    public static ReportPriority getReportPriority(final int value) {
        ReportPriority priority;
        switch (value) {
            case HIGH_PRIORITY_VALUE:
                priority = ReportPriority.HIGH_PRIORITY;
                break;
            case MED_PRIORITY_VALUE:
                priority = ReportPriority.MED_PRIORITY;
                break;
            case LOW_PRIORITY_VALUE:
                priority = ReportPriority.LOW_PRIORITY;
                break;
            default:
                log.error("No priority found for reports. The int {} is not valid (only 1, 2, 3 allowed). Defaulting to LOW priority",
                        String.valueOf(value));
                priority = ReportPriority.LOW_PRIORITY;
                break;
        }
        return priority;
    }
}
