package com.qmth.teachcloud.common.enums;


import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum AssignEnum {
    NEED_ASSIGN_SCORE("是","需要且按照公式赋分"),
    NO_NEED_ASSIGN_SCORE("否","不需要赋分，标准分即为赋分"),
    SPECIAL_ASSIGN_SCORE("特殊赋分","特殊赋分，按照excel表进行赋分"),
    ;
    private final String type;
    private final String desc;

    AssignEnum(String type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    public String getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据枚举类属性type查找枚举类
     * @param type 赋分类型
     * @return 枚举类
     */
    public static AssignEnum convertToEnum(String type){
        List<AssignEnum> assignEnumList = Arrays.stream(AssignEnum.values())
                .filter(e -> type.equals(e.getType())).distinct().collect(Collectors.toList());
        if (assignEnumList.size() != 1){
            throw ExceptionResultEnum.ERROR.exception("赋分类型不属于现有类型" + "[" + type + "]");
        }
        return assignEnumList.get(0);
    }
}
