package com.arms.egovframework.javaservice.esframework.esquery.filter;

import com.arms.egovframework.javaservice.esframework.esquery.must.QueryStringMust;
import org.opensearch.index.query.AbstractQueryBuilder;
import org.opensearch.index.query.Operator;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.index.query.QueryStringQueryBuilder;
import org.springframework.util.ObjectUtils;


public class QueryStringFilter extends Filter<QueryStringQueryBuilder> {

    private QueryStringQueryBuilder queryBuilder;

    private QueryStringFilter(String queryString){
        if(!ObjectUtils.isEmpty(queryString)){
            this.queryBuilder = QueryBuilders.queryStringQuery(queryString);
        }
    }

    public static QueryStringFilter of(String queryString){
        return new QueryStringFilter(queryString);
    }

    public QueryStringFilter operator(Operator operator){
        if(operator!=null){
            this.queryBuilder.defaultOperator(operator);
        }
        return this;
    }


    @Override
    public AbstractQueryBuilder<QueryStringQueryBuilder> abstractQueryBuilder() {
        return queryBuilder;
    }
}
