package com.ningdatech.carapi.datascope.contants;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * <p>
 * 数据权限枚举类
 * </p>
 *
 * @author WendyYang
 * @since 2019-07-21
 */
@Getter
@AllArgsConstructor
public enum DataScopeEnum {

    /**
     * 数据权限枚举
     */
    ALL(1, "全部"),

    SELF_REGION(2, "本区域"),

    SELF_CHILD_REGION(3, "本区域及下级区域"),

    SELF_COMPANY(4, "本单位");

    private final int val;

    private final String desc;


    public static DataScopeEnum match(String val) {
        return Stream.of(values())
                .filter((item) -> item.name().equalsIgnoreCase(val))
                .findAny()
                .orElse(SELF_COMPANY);
    }

    public static DataScopeEnum get(String val) {
        return match(val);
    }

    public boolean eq(final DataScopeEnum val) {
        return val != null && this.name().equals(val.name());
    }

    public int getCode() {
        return this.val;
    }

}
