<?php
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: google/datastore/v1/query.proto

namespace Google\Cloud\Datastore\V1;

use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBUtil;
use Google\Protobuf\RepeatedField;

/**
 * Datastore query for running an aggregation over a
 * [Query][google.datastore.v1.Query].
 *
 * Generated from protobuf message <code>google.datastore.v1.AggregationQuery</code>
 */
class AggregationQuery extends \Google\Protobuf\Internal\Message
{
    /**
     * Optional. Series of aggregations to apply over the results of the
     * `nested_query`.
     * Requires:
     * * A minimum of one and maximum of five aggregations per query.
     *
     * Generated from protobuf field <code>repeated .google.datastore.v1.AggregationQuery.Aggregation aggregations = 3 [(.google.api.field_behavior) = OPTIONAL];</code>
     */
    private $aggregations;
    protected $query_type;

    /**
     * Constructor.
     *
     * @param array $data {
     *     Optional. Data for populating the Message object.
     *
     *     @type \Google\Cloud\Datastore\V1\Query $nested_query
     *           Nested query for aggregation
     *     @type \Google\Cloud\Datastore\V1\AggregationQuery\Aggregation[] $aggregations
     *           Optional. Series of aggregations to apply over the results of the
     *           `nested_query`.
     *           Requires:
     *           * A minimum of one and maximum of five aggregations per query.
     * }
     */
    public function __construct($data = NULL) {
        \GPBMetadata\Google\Datastore\V1\Query::initOnce();
        parent::__construct($data);
    }

    /**
     * Nested query for aggregation
     *
     * Generated from protobuf field <code>.google.datastore.v1.Query nested_query = 1;</code>
     * @return \Google\Cloud\Datastore\V1\Query|null
     */
    public function getNestedQuery()
    {
        return $this->readOneof(1);
    }

    public function hasNestedQuery()
    {
        return $this->hasOneof(1);
    }

    /**
     * Nested query for aggregation
     *
     * Generated from protobuf field <code>.google.datastore.v1.Query nested_query = 1;</code>
     * @param \Google\Cloud\Datastore\V1\Query $var
     * @return $this
     */
    public function setNestedQuery($var)
    {
        GPBUtil::checkMessage($var, \Google\Cloud\Datastore\V1\Query::class);
        $this->writeOneof(1, $var);

        return $this;
    }

    /**
     * Optional. Series of aggregations to apply over the results of the
     * `nested_query`.
     * Requires:
     * * A minimum of one and maximum of five aggregations per query.
     *
     * Generated from protobuf field <code>repeated .google.datastore.v1.AggregationQuery.Aggregation aggregations = 3 [(.google.api.field_behavior) = OPTIONAL];</code>
     * @return RepeatedField<\Google\Cloud\Datastore\V1\AggregationQuery\Aggregation>
     */
    public function getAggregations()
    {
        return $this->aggregations;
    }

    /**
     * Optional. Series of aggregations to apply over the results of the
     * `nested_query`.
     * Requires:
     * * A minimum of one and maximum of five aggregations per query.
     *
     * Generated from protobuf field <code>repeated .google.datastore.v1.AggregationQuery.Aggregation aggregations = 3 [(.google.api.field_behavior) = OPTIONAL];</code>
     * @param \Google\Cloud\Datastore\V1\AggregationQuery\Aggregation[] $var
     * @return $this
     */
    public function setAggregations($var)
    {
        $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Datastore\V1\AggregationQuery\Aggregation::class);
        $this->aggregations = $arr;

        return $this;
    }

    /**
     * @return string
     */
    public function getQueryType()
    {
        return $this->whichOneof("query_type");
    }

}

