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

import lombok.Getter;

import java.util.Arrays;

/**
 * <p>
 * 数据权限可见范围枚举
 * </p>
 *
 * @author WendyYang
 * @since 15:59 2023/1/28
 */
@Getter
public enum DataScopeEnum {

    /**
     * 数据权限可见范围
     */
    CURRENT_ORG("本单位", 1),
    CURRENT_AND_SUB_ORG("本单位及下属单位", 2),
    CURRENT_REGION("当前区域", 3),
    CURRENT_CITY("全市", 4);

    private final String desc;
    private final Integer code;

    DataScopeEnum(String desc, Integer code) {
        this.code = code;
        this.desc = desc;
    }

    public boolean eq(Integer code) {
        return this.code.equals(code);
    }

    /**
     * 根据code获取枚举实例
     *
     * @param code 编码
     * @return {@link DataScopeEnum}
     * @author WendyYang
     **/
    public static DataScopeEnum getByCode(Integer code) {
        return Arrays.stream(values())
                .filter(w -> w.eq(code))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("无效的数据权限可见范围编码"));
    }

}
