package com.chain.api;

import com.chain.exception.ChainException;
import com.chain.http.Context;
import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;

public abstract class BaseQueryBuilder<T extends BaseQueryBuilder<T>> {
  @SerializedName("query")
  protected Query query;

  public abstract <S extends PagedItems> S execute(Context ctx) throws ChainException;

  public BaseQueryBuilder() {
    this.query = new Query();
  }

  public T useIndexById(String id) {
    this.query.indexId = id;
    return (T) this;
  }

  public T useIndexByAlias(String alias) {
    this.query.indexAlias = alias;
    return (T) this;
  }

  public T withFilter(String filter) {
    this.query.filter = filter;
    return (T) this;
  }

  public T addFilterParameter(String param) {
    this.query.filterParams.add(param);
    return (T) this;
  }

  public T setFilterParameters(ArrayList<String> params) {
    this.query.filterParams = new ArrayList<>();
    for (String p : params) {
      this.query.filterParams.add(p);
    }
    return (T) this;
  }
}

@@ -638,32 +638,124 @@
  (T) this;%0A  %7D%0A%0A
+  public T setAfter(String after) %7B%0A    this.query.after = after;%0A    return (T) this;%0A  %7D%0A%0A
   public T withF

set after on queries