package com.capgemini.reports.definition.r20report;

import lombok.extern.slf4j.Slf4j;

/**
 * Enumeration of the Classe field's possible values.
 */
@Slf4j
public enum Classe {
    /**
     * The value 1.
     */
    CLASSE_1 {
        @Override
        public String toString() {
            return "1";
        }
    },
    /**
     * The value 2.
     */
    CLASSE_2 {
        @Override
        public String toString() {
            return "2";
        }
    };

    /**
     * Parses the input {@link String} and returns the corresponding enum instance.<br>
     * Default value: Classe 1
     *
     * @param classeStr the input string
     * @return the enum instance
     */
    public static Classe parse(final String classeStr) {
        try {
            int intValue = Integer.parseInt(classeStr);
            if (intValue == 1) {
                return CLASSE_1;
            } else if (intValue == 2) {
                return CLASSE_2;
            } else {
                log.warn("Could not decide between Classe 1 and Classe 2 for input '{}', defaulting to Classe 1", classeStr);
            }
        } catch (NumberFormatException e) {
            log.info("Bad user input: not a number", e);
        }
        return CLASSE_2; // Default value
    }
}
