package com.purui.prims.common.pojo.enums;


import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum FilterOperatorEnum {
    IN("IN"),
    NOT_IN("NOT_IN"),
    EQUALS("="),
    BETWEEN("BETWEEN"),
    MORE_THAN(">"),
    MORE_THAN_EQUALS(">="),
    IS_NULL("IS_NULL"),
    IS_NOT_NULL("IS_NOT_NULL"),
    LIKE("LIKE"),
    LESS_THAN("<"),
    LESS_THAN_EQUALS("<="),
    NOT_EQUALS("!="),
    EXISTS("EXISTS");

    private String value;

    FilterOperatorEnum(String value) {
        this.value = value;
    }

    @JsonCreator
    public static FilterOperatorEnum getSqlOperator(String type) {
        for (FilterOperatorEnum operatorEnum : FilterOperatorEnum.values()) {
            if (operatorEnum.value.equalsIgnoreCase(type) || operatorEnum.name().equalsIgnoreCase(type)) {
                return operatorEnum;
            }
        }
        return null;
    }

    @JsonValue
    public String getValue() {
        return value;
    }

    public static boolean isValueCompare(FilterOperatorEnum filterOperatorEnum) {
        return EQUALS.equals(filterOperatorEnum) || MORE_THAN.equals(filterOperatorEnum)
               || MORE_THAN_EQUALS.equals(filterOperatorEnum) || LESS_THAN.equals(filterOperatorEnum)
               || LESS_THAN_EQUALS.equals(filterOperatorEnum) || NOT_EQUALS.equals(filterOperatorEnum);
    }

}
