package com.qmth.paper.library.common.enums;

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

/**
 * 角色来源
 * @Date: 2021/3/23.
 */
public enum RoleSourceEnum {

    SYS("系统内置");

    RoleSourceEnum(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 (RoleSourceEnum value : RoleSourceEnum.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 RoleSourceEnum convertDescToEnum(String desc){
        RoleSourceEnum res = null;
        for (RoleSourceEnum value : RoleSourceEnum.values()) {
            if (desc.equals(value.getDesc())) {
                res = value;
            }
        }
        return res;
    }
}
