package com.ningdatech.pmapi.sys.model.enumeration;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

/**
 * <p>
 * 实体注释中生成的类型枚举
 * 角色的资源
 * </p>
 *
 * @author PoffyZhang
 * @since 2022-09-30
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "AuthorizeType", description = "权限类型-枚举")
public enum AuthorizeTypeEnum {

    /**
     * MENU="菜单"
     */
    MENU("菜单"),
    DATA("数据"),
    /**
     * RESOURCE="资源"
     */
    RESOURCE("资源");

    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static AuthorizeTypeEnum match(String val, AuthorizeTypeEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static AuthorizeTypeEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(AuthorizeTypeEnum val) {
        return val != null && getCode().equals(val.name());
    }

    @ApiModelProperty(value = "编码", allowableValues = "MENU,RESOURCE", example = "MENU")
    public String getCode() {
        return this.name();
    }

}
