import "message-wrapping.proto";

package org.infinispan.client.hotrod.impl.query;

message QueryRequest {

   /**
    * The query string, expressed in JPA query language.
    * NOTE: currently only a limited subset of the JPA query language is supported.
    */
   required string jpqlString = 1;

   message SortCriteria {

      /**
       * Dot separated attribute path to sort by.
       */
      required string attributePath = 1;

      /**
       * Sort direction.
       */
      required bool isAscending = 2;
   }

   //TODO ideally, the sort criteria should be in the jpql string but currently the used HQL parser does not support this
   repeated SortCriteria sortCriteria = 2;

   /**
    * The number of matching results to skip before the first returned result.
    */
   required int64 startOffset = 3;

   /**
    * Maximum number of matching results to return.
    */
   required int32 maxResults = 4;
}

message QueryResponse {

   /**
    * The number of returned results.
    */
   required int32 numResults = 1;

  /**
   * Indicates presence and size of projections.
   *
   *      0 - no projection
   * 1 .. N - projection with N components
   *    < 0 - illegal value
   */
   required int32 projectionSize = 2;

   /**
    * The list of matching results. The size should be either numResults, if no projections are used, or numResults *
    * projectionSize otherwise. If projections are used, then each group of projectionSize consecutive elements
    * represent together a result.
    */
   repeated org.infinispan.protostream.WrappedMessage results = 3;

   required int64 totalResults = 4;
}
