/*
 * Copyright (c) 2015 Spotify AB.
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package com.spotify.heroic;

import static java.util.Optional.ofNullable;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class QueryOptions {
    public static final boolean DEFAULT_TRACING = false;

    public static final QueryOptions DEFAULTS = new QueryOptions(DEFAULT_TRACING);

    // XXX: remove ones deployed everywhere.
    @Getter
    private final String type = "core";

    /**
     * Indicates if tracing is enabled.
     *
     * Traces queries will include a {@link QueryTrace} object that indicates detailed timings of
     * the query.
     *
     * @return {@code true} if tracing is enabled.
     */
    private final boolean tracing;

    @JsonCreator
    public QueryOptions(@JsonProperty("tracing") Boolean tracing) {
        this.tracing = ofNullable(tracing).orElse(DEFAULT_TRACING);
    }

    public boolean isTracing() {
        return tracing;
    }

    public static QueryOptions defaults() {
        return DEFAULTS;
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {
        private boolean tracing = false;

        public Builder tracing(boolean tracing) {
            this.tracing = tracing;
            return this;
        }

        public QueryOptions build() {
            return new QueryOptions(tracing);
        }
    }
}

@@ -914,16 +914,44 @@
 lable;%0A%0A
+import java.util.Optional;%0A%0A
 import c
@@ -1048,16 +1048,61 @@
 roperty;
+%0Aimport com.spotify.heroic.metric.QueryTrace;
 %0A%0Aimport
@@ -1348,16 +1348,34 @@
 _TRACING
+, Optional.empty()
 );%0A%0A    
@@ -1741,16 +1741,135 @@
 acing;%0A%0A
+    /**%0A     * The number of entries to fetch for every batch.%0A     */%0A    private final Optional%3CInteger%3E fetchSize;%0A%0A
     @Jso
@@ -1933,32 +1933,100 @@
  Boolean tracing
+,%0A            @JsonProperty(%22fetchSize%22) Optional%3CInteger%3E fetchSize
 ) %7B%0A        this
@@ -2081,16 +2081,52 @@
 ACING);%0A
+        this.fetchSize = fetchSize;%0A
     %7D%0A%0A 
@@ -2180,32 +2180,111 @@
 tracing;%0A    %7D%0A%0A
+    public Optional%3CInteger%3E getFetchSize() %7B%0A        return fetchSize;%0A    %7D%0A%0A
     public stati
@@ -2488,24 +2488,88 @@
 ing = false;
+%0A        private Optional%3CInteger%3E fetchSize = Optional.empty();
 %0A%0A        pu
@@ -2676,24 +2676,163 @@
 %0A        %7D%0A%0A
+        public Builder fetchSize(int fetchSize) %7B%0A            this.fetchSize = Optional.of(fetchSize);%0A            return this;%0A        %7D%0A%0A
         publ
@@ -2900,16 +2900,27 @@
 (tracing
+, fetchSize
 );%0A     

make fetch size configurable for QueryOptions