package com.wx.application.nebula.graph.query;

import com.wx.application.util.JSONUtils;

import cn.hutool.core.util.StrUtil;
import lombok.Data;

@Data
public class TermQuery {
	
	public enum Operator {
        EQ,//值相等
        CONTAINS, //值模糊匹配
        STARTSWITH
    }

    public enum Logic {
        AND, OR
    }


    //字段名称
    public String fieldName;
    //值
    public Object value;
    //eq ue
    public Operator operator = Operator.EQ;
    //and or
    public Logic logic = Logic.AND;
    
    public TermQuery(String fieldName, Operator operator, Object value) {
        this.fieldName = fieldName;
        this.value = value;
        this.operator = operator;
    }
    
    public String toString() {
    	StringBuffer sb = new StringBuffer();
    	sb.append(fieldName);
    	switch (operator) {
		case EQ:
			sb.append("==");
			break;
		case CONTAINS:
			sb.append(" CONTAINS ");
			break;
		case STARTSWITH:
			sb.append(" STARTS WITH ");
			break;
		default:
			break;
		}
		if(value instanceof String) {
			sb.append(JSONUtils.c(value));
		} else {
			sb.append(StrUtil.format("{}", value));
		}
    	return sb.toString();
    }
    
}
