/**********************************************************************************************************************
 *                                  REMOTE QUERY RELATED PROTOBUF DEFINITIONS                                         *
 *                                                                                                                    *
 *         Allocated TypeId range is: [4400 .. 4599] (see org.infinispan.commons.marshall.ProtoStreamTypeIds)         *
 *         Actually used range is: [4400 .. 4403]                                                                     *
 *********************************************************************************************************************/

import "org/infinispan/protostream/message-wrapping.proto";

package org.infinispan.query.remote.client;

/**
 * @TypeId(4400)
 */
message QueryRequest {

   /**
    * The query string, in Infinispan's query language aka Ickle (a JP-QL micro-subset with full-text enhancements).
    */
   required string queryString = 1;

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

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

   /**
    * Multiple, optional, named parameters. Each name must occur only once.
    */
   repeated NamedParameter namedParameters = 5;

   /**
    * Whether the query is limited to the data from node that receives the request
    */
   optional bool local = 6;

   message NamedParameter {

      /**
       * Parameter unique name.
       */
      required string name = 1;

      /**
       * Parameter value.
       */
      required org.infinispan.protostream.WrappedMessage value = 2;
   }
}

/**
 * @TypeId(4401)
 */
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 row from the result. We use this simple schema in order to avoid bi-dimensional arrays when
    * projections are present.
    */
   repeated org.infinispan.protostream.WrappedMessage results = 3;

   /**
    * Total number of results that match the query. This is usually larger than numResults due to
    * QueryRequest.startOffset and QueryRequest.maxResults.
    */
   required int64 totalResults = 4;
}

/**
 * @TypeId(4402)
 */
message FilterResult {

   optional bytes instance = 1;

   repeated org.infinispan.protostream.WrappedMessage projection = 2;

   repeated org.infinispan.protostream.WrappedMessage sortProjection = 3;
}

/**
 * @TypeId(4403)
 */
message ContinuousQueryResult {

   enum ResultType {
      LEAVING = 0;
      JOINING = 1;
      UPDATED = 2;
   }

   required ResultType resultType = 1;

   required bytes key = 2;

   /* Only present if resultType is JOINING or UPDATED and 'projection' field is missing */
   optional bytes value = 3;

   /* Only present if resultType is JOINING or UPDATED and 'value' field is missing */
   repeated org.infinispan.protostream.WrappedMessage projection = 4;
}
