package com.greenorange.promotion.model.enums;

import com.greenorange.promotion.annotation.BaseEnum;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;


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

/**
 * 用户角色枚举
 */
@Getter
public enum UserRoleEnum implements BaseEnum {

    USER("用户", "user"),
    ADMIN("管理员", "admin"),
    BOSS("Boss", "boss"),
    BAN("被封号", "ban"),
    MANAGER("经理", "manager"),
    SUPERVISOR("主管", "supervisor"),
    STAFF("员工", "staff");


    private final String text;

    private final String value;

    UserRoleEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * BaseEnum 要求的方法：返回这个枚举的“校验值”
     */
    @Override
    public String getValue() {
        return this.value;
    }

    /**
     * 获取值列表
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    /**
     * 获取值列表
     */
    public static UserRoleEnum getEnumByValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (UserRoleEnum anEnum : UserRoleEnum.values()) {
            if(anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }


}
