/*
 * Licensed to STRATIO (C) under one or more contributor license agreements.
 * See the NOTICE file distributed with this work for additional information
 * regarding copyright ownership.  The STRATIO (C) 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.stratio.cassandra.lucene.search.condition.builder;

import com.stratio.cassandra.lucene.search.condition.GeoDistance;
import com.stratio.cassandra.lucene.search.condition.GeoTransformation;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.annotate.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Andres de la Pena {@literal <adelapena@stratio.com>}
 */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({@JsonSubTypes.Type(value = GeoTransformationBuilder.Buffer.class, name = "buffer")})
public interface GeoTransformationBuilder<T extends GeoTransformation> {

    T build();

    @JsonTypeName("clipper")
    final class Buffer implements GeoTransformationBuilder<GeoTransformation.Buffer> {

        protected static final Logger logger = LoggerFactory.getLogger(GeoTransformationBuilder.class);

        /** The max allowed distance. */
        @JsonProperty("max_distance")
        private final String maxDistance;

        /** The min allowed distance. */
        @JsonProperty("min_distance")
        private String minDistance;

        @JsonCreator
        public Buffer(@JsonProperty("max_distance") String maxDistance) {
            this.maxDistance = maxDistance;
        }

        /**
         * Sets the min allowed distance.
         *
         * @param minDistance the min distance
         * @return this with the specified min distance
         */
        public Buffer setMinDistance(String minDistance) {
            this.minDistance = minDistance;
            return this;
        }

        /** {@inheritDoc}*/
        @Override
        public GeoTransformation.Buffer build() {
            GeoDistance min = StringUtils.isBlank(minDistance) ? null : GeoDistance.parse(minDistance);
            GeoDistance max = StringUtils.isBlank(maxDistance) ? null : GeoDistance.parse(maxDistance);
            return new GeoTransformation.Buffer(max, min);
        }

    }
}

@@ -1802,22 +1802,16 @@
 private 
-final 
 String m
@@ -1814,32 +1814,32 @@
 ng maxDistance;%0A
+
 %0A        /** The
@@ -1951,20 +1951,179 @@
     
-@JsonCreator
+/**%0A         * Sets the max allowed distance.%0A         *%0A         * @param maxDistance the max distance%0A         * @return this with the specified max distance%0A         */
 %0A   
@@ -2144,39 +2144,24 @@
 ffer
-(@JsonProperty(%22max_d
+ setMaxD
 istance
-%22) 
+(
 Stri
@@ -2214,32 +2214,57 @@
  = maxDistance;%0A
+            return this;%0A
         %7D%0A%0A     

Set max distance is not an mandatory argument of buffer transformation.