package kr.co.hanwha.hifive.enums;

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

/**
 * Created by aaron on 2019. 3. 7.
 */

public enum ProjectAchievementType {
    NULL(-1),
    /**
     * 0 ~ 39
     */
    RED(0),
    /**
     * 40 ~ 59
     */
    ORANGE(40),
    /**
     * 60 ~ 99
     */
    YELLOW(60),
    /**
     * 100 이상
     */
    GREEN(100);

    private int mType;
    private static Map map = new HashMap<>();

    ProjectAchievementType(int type) {
        mType = type;
    }

    public int getCode() {
        return mType;
    }

    static {
        for (ProjectAchievementType type : values()) {
            map.put(type.mType, type);
        }
    }

    /**
     * 달성도 범위에 따른 타입 전달
     *
     * @param value 달성도
     * @return 달성도 타입
     */
    public static ProjectAchievementType valueOf(int value) {
        if (value >= GREEN.mType) return GREEN;
        else if (value >= YELLOW.mType) return YELLOW;
        else if (value >= ORANGE.mType) return ORANGE;
        else if (value >= RED.mType) return RED;
        else return GREEN;
//        return (ProjectAchievementType) map.get(value);
    }
}
