package com.qmth.teachcloud.common.enums;

import java.util.ArrayList;
import java.util.List;

/**
 * 角色类型
 * @Date: 2021/3/23.
 */
public enum RoleTypeEnum {

    ADMIN("系统管理员"),
    SCHOOL_ADMIN("学校管理员"),
    EXAM_TEACHER("考务老师"),
    QUESTION_TEACHER("命题老师"),
    CUSTOMER("客服员"),
    PRINTER("印刷员"),
    CUSTOM("自定义"),
    OFFICE_TEACHER("教务处老师"),
    PRESIDENT("学院院长"),
    TEACHER("任课老师"),
    MARKER("评卷员"),
    MARKER_LEADER("课组长");

    RoleTypeEnum(String desc) {
        this.desc = desc;
    }

    private String desc;

    public String getDesc() {
        return desc;
    }

    /**
     * @param hasAdmin 是否需要管理员
     * @return
     */
    public static List<EnumResult> listTypes(boolean hasAdmin) {
        List<EnumResult> list = new ArrayList<EnumResult>();
        for (RoleTypeEnum value : RoleTypeEnum.values()) {
            if (!hasAdmin && "ADMIN".equals(value.name())) {
                continue;
            }
            EnumResult result = new EnumResult();
            result.setName(value.name());
            result.setOrdinal(value.ordinal());
            result.setCode(null);
            result.setDesc(value.getDesc());
            list.add(result);
        }
        return list;
    }

    /**
     * 根据desc查找枚举类
     * @param desc desc
     * @return 枚举类
     */
    public static RoleTypeEnum convertDescToEnum(String desc){
        RoleTypeEnum res = null;
        for (RoleTypeEnum value : RoleTypeEnum.values()) {
            if (desc.equals(value.getDesc())) {
                res = value;
            }
        }
        return res;
    }
}
