package io.citrine.jcc.search.pif.query;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonSetter;

/**
 * Class for defining queries against PIF records on Citrination.
 *
 * @author Kyle Michel
 */
public class PifQuery {

    /**
     * Index of the first hit that should be returned.
     *
     * @param from Index of the first hit (inclusive of zero) that should be returned.
     * @return This object.
     */
    @JsonSetter("from")
    public PifQuery from(final Integer from) {
        this.from = from;
        return this;
    }

    /**
     * Get the index of the first hit that should be returned.
     *
     * @return Index of the first hit that should be returned or a null pointer if not set.
     */
    @JsonGetter("from")
    public Integer from() {
        return this.from;
    }

    /**
     * Set the maximum number of records that should be returned.
     *
     * @param size Maximum number of records to return.
     * @return This object.
     */
    @JsonSetter("size")
    public PifQuery size(final Integer size) {
        this.size = size;
        return this;
    }

    /**
     * Get the maximum number of records that should be returned.
     *
     * @return Maximum number of records that should be returned or a null pointer if not set.
     */
    @JsonGetter("size")
    public Integer size() {
        return this.size;
    }

    /**
     * Whether to return the actual record that was matched. If extractions are being made in the query, then it may
     * not be necessary to actually return the system. Defaults to true.
     *
     * @param returnSystem True to return systems in the results.
     * @return This object.
     */
    @JsonSetter("returnSystem")
    public PifQuery returnSystem(final Boolean returnSystem) {
        this.returnSystem = returnSystem;
        return this;
    }

    /**
     * Get whether systems should be return in the results set.
     *
     * @return True if systems should be returned in the results or a null pointer if it is not set.
     */
    @JsonGetter("returnSystem")
    public Boolean returnSystem() {
        return this.returnSystem;
    }

    /**
     * Set whether Latex formatting should be added.
     *
     * @param addLatex True to add latex.
     * @return This object.
     */
    @JsonSetter("addLatex")
    public PifQuery addLatex(final Boolean addLatex) {
        this.addLatex = addLatex;
        return this;
    }

    /**
     * Get whether latex formatting should be added to results.
     *
     * @return True if Latex should be added to results.
     */
    @JsonGetter("addLatex")
    public Boolean addLatex() {
        return this.addLatex;
    }

    /**
     * Set information about a field to sort on. This works on fields that have been marked with an extractAs value.
     *
     * @param sortExtracted {@link SortExtracted} with information about the extracted field to sort on.
     * @return This object.
     */
    @JsonSetter("sortExtracted")
    public PifQuery sortExtracted(final SortExtracted sortExtracted) {
        this.sortExtracted = sortExtracted;
        return this;
    }

    /**
     * Get information about an extracted field to sort on.
     *
     * @return {@link SortExtracted} object or a null pointer if it has not been set.
     */
    @JsonGetter("sortExtracted")
    public SortExtracted sortExtracted() {
        return this.sortExtracted;
    }

    /**
     * Set the system query.
     *
     * @param system {@link SystemQuery} object to use.
     * @return This object.
     */
    @JsonSetter("system")
    public PifQuery system(final SystemQuery system) {
        this.system = system;
        return this;
    }

    /**
     * Get the system query to apply.
     *
     * @return {@link SystemQuery} object or a null pointer if one has not been set.
     */
    @JsonGetter("system")
    public SystemQuery system() {
        return this.system;
    }

    /** Index of the first hit that should be returned. */
    private Integer from;

    /** Total number of hits the should be returned. */
    private Integer size;

    /** Whether to include the system in the results. */
    private Boolean returnSystem;

    /** Whether to add latex formatting to results. */
    private Boolean addLatex;

    /** Information about an extracted field to sort on. */
    private SortExtracted sortExtracted;

    /** System query to apply. */
    private SystemQuery system;
}
@@ -131,22 +131,135 @@
 ion.Json
-Setter
+Ignore;%0Aimport com.fasterxml.jackson.annotation.JsonSetter;%0Aimport io.citrine.jcc.util.ListUtil;%0A%0Aimport java.util.List
 ;%0A%0A/**%0A 
@@ -2819,32 +2819,457 @@
 ddLatex;%0A    %7D%0A%0A
+    /**%0A     * Set information about all of the fields to sort on.%0A     *%0A     * @param sortExtracted List of %7B@link SortExtracted%7D objects to sort on.%0A     * @return This object.%0A     */%0A    @JsonSetter(%22sortExtracted%22)%0A    private void sortExtracted(final List%3CSortExtracted%3E sortExtracted) %7B  // Private since only Jackson should use it%0A        this.sortExtracted = ListUtil.add(sortExtracted, this.sortExtracted);%0A    %7D%0A%0A
     /**%0A     * S
@@ -3373,24 +3373,24 @@
 ctAs value.%0A
-
      *%0A     
@@ -3534,39 +3534,22 @@
    @Json
-Setter(%22sortExtracted%22)
+Ignore
 %0A    pub
@@ -3641,29 +3641,63 @@
 acted = 
-sortExtracted
+ListUtil.add(sortExtracted, this.sortExtracted)
 ;%0A      
@@ -3931,16 +3931,25 @@
  public 
+Iterable%3C
 SortExtr
@@ -3945,32 +3945,33 @@
 le%3CSortExtracted
+%3E
  sortExtracted()
@@ -3988,34 +3988,304 @@
  return 
-this.sortExtracted
+ListUtil.iterable(this.sortExtracted);%0A    %7D%0A%0A    /**%0A     * Return whether this object contains any sorts.%0A     *%0A     * @return True if this object contains any sorts.%0A     */%0A    @JsonIgnore%0A    public boolean hasSortExtracted() %7B%0A        return ListUtil.hasContent(this.sortExtracted)
 ;%0A    %7D%0A
@@ -5220,16 +5220,21 @@
 private 
+List%3C
 SortExtr
@@ -5230,32 +5230,33 @@
 st%3CSortExtracted
+%3E
  sortExtracted;%0A

allow sorting by multiple fields