package com.persagy.dmp.basic.model;

import lombok.Getter;

/**
 * 查询条件
 * @author Charlie Yu
 * @date 2021-06-25
 */
@Getter
public enum QueryOperator {

    /** 查询条件 */
    NE("$ne", "不等于"),
    GT("$gt", "大于"),
    GTE("$gte", "大于等于"),
    LT("$lt", "小于"),
    LTE("$lte", "小于等于"),
    IN("$in", "等于"),
    LIKE("$like", "包含"),
    NOT_LIKE("$notLike", "不包含"),
    NULL("$null", "空"),

    CONTAINS("$contains", "包含"),
    NOT_CONTAINS("$notcontains", "不包含"),
    SEARCH("$search", "匹配"),
    RELATION_FROM("relationFrom", "关系来源"),
    RELATION_TO("relationTo", "关系目标"),

    /** 暂不使用 */
    SQL("$sql", "SQL"),
    /** 20210816 支持relation条件 */
    IN_SQL("$inSql", "IN_SQL"),
    NOT_IN_SQL("$notInSql", "NOT_IN_SQL"),
    /** 20210816 支持or条件 */
    AND("$and", "且"),
    OR("$or", "或"),
    AND_OR("$andOr", "且中或"),
    /** 20210816 支持数据中心左、右like条件 */
    LIKE_LEFT("$likeLeft", "左包含"),
    LIKE_RIGHT("$likeRight", "右包含");

    private String index;
    private String name;

    QueryOperator(String index, String name) {
        this.index = index;
        this.name = name;
    }

    /**
     * 通过Index查找
     * @param index
     * @return
     */
    public static QueryOperator findByIndex(String index) {
        QueryOperator[] values = QueryOperator.values();
        for(QueryOperator value:values) {
            if(value.getIndex().equalsIgnoreCase(index)) {
                return value;
            }
        }
        return null;
    }
}
