package com.tuoheng.admin.enums;

import lombok.Getter;

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

/**
 *  用户类型
 *
 * @author wanjing
 * @team tuoheng
 * @date 2022-11-25
 */
public enum RoleEnum {

    SUPER_ADMIN(1,"超级管理员"),
    ADMIN(2,"管理员"),
    ORDINARY_USER(3,"普通用户");

    RoleEnum(int code, String description){
        this.code = code;
        this.description = description;
    }

    @Getter
    private int code;

    @Getter
    private String description;

    private static Map<Integer, RoleEnum> data = new HashMap<>();

    static {
        for (RoleEnum type : RoleEnum.values()) {
            data.put(type.code, type);
        }
    }

    public static RoleEnum parse(int code) {
        if (data.containsKey(code)) {
            return data.get(code);
        }
        return null;
    }
}
