package com.byteowls.vaadin.chartjs.options.scale;

import com.byteowls.vaadin.chartjs.utils.JUtils;
import com.byteowls.vaadin.chartjs.utils.JsonBuilder;
import elemental.json.JsonObject;

/**
 * @author michael@byteowls.com
 */
public class LinearTicks<T> extends Ticks<T> implements JsonBuilder {

    private static final long serialVersionUID = -7751881366365153424L;

    private Boolean beginAtZero;
    private Integer min;
    private Integer max;
    private Integer maxTicksLimit;
    private Double fixedStepSize;
    private Double stepSize;
    private Integer suggestedMax;
    private Integer suggestedMin;

    public LinearTicks(T parent) {
        super(parent);
    }

    /**
     * if true, scale will include 0 if it is not already included.
     */
    public LinearTicks<T> beginAtZero(Boolean beginAtZero) {
        this.beginAtZero = beginAtZero;
        return this;
    }

    /**
     * User defined minimum number for the scale, overrides minimum value from data.
     */
    public LinearTicks<T> min(int min) {
        this.min = min;
        return this;
    }

    /**
     * User defined maximum number for the scale, overrides maximum value from data.
     */
    public LinearTicks<T> max(int max) {
        this.max = max;
        return this;
    }

    /**
     * Maximum number of ticks and gridlines to show. If not defined, it will limit to 11 ticks but will show all gridlines.
     */
    public LinearTicks<T> maxTicksLimit(int maxTicksLimit) {
        this.maxTicksLimit = maxTicksLimit;
        return this;
    }

    /**
     * User defined fixed step size for the scale. If set, the scale ticks will be enumerated by multiple of stepSize, having one tick per increment.
     * If not set, the ticks are labeled automatically using the nice numbers algorithm.
     */
    public LinearTicks<T> fixedStepSize(double fixedStepSize) {
        this.fixedStepSize = fixedStepSize;
        return this;
    }

    /**
     * if defined, it can be used along with the min and the max to give a custom number of steps. See the example below.
     */
    public LinearTicks<T> stepSize(double stepSize) {
        this.stepSize = stepSize;
        return this;
    }

    /**
     * User defined maximum number for the scale, overrides maximum value except for if it is lower than the maximum value.
     */
    public LinearTicks<T> suggestedMax(int suggestedMax) {
        this.suggestedMax = suggestedMax;
        return this;
    }

    /**
     * User defined minimum number for the scale, overrides minimum value except for if it is higher than the minimum value.
     */
    public LinearTicks<T> suggestedMin(int suggestedMin) {
        this.suggestedMin = suggestedMin;
        return this;
    }


    @Override
    public JsonObject buildJson() {
        JsonObject map = super.buildJson();
        JUtils.putNotNull(map, "beginAtZero", beginAtZero);
        JUtils.putNotNull(map, "min", min);
        JUtils.putNotNull(map, "max", max);
        JUtils.putNotNull(map, "maxTicksLimit", maxTicksLimit);
        JUtils.putNotNull(map, "fixedStepSize", fixedStepSize);
        JUtils.putNotNull(map, "stepSize", stepSize);
        JUtils.putNotNull(map, "suggestedMin", suggestedMin);
        JUtils.putNotNull(map, "suggestedMax", suggestedMax);
        return map;
    }
}

@@ -412,23 +412,22 @@
 private 
-Integer
+Double
  min;%0A  
@@ -432,31 +432,30 @@
     private 
-Integer
+Double
  max;%0A    pr
@@ -550,39 +550,38 @@
 ze;%0A    private 
-Integer
+Double
  suggestedMax;%0A 
@@ -591,23 +591,22 @@
 private 
-Integer
+Double
  suggest
@@ -1056,175 +1056,587 @@
 n = 
-min;%0A        return this;%0A    %7D%0A%0A    /**%0A     * User defined maximum number for the scale, overrides maximum value from data.%0A     */%0A    public LinearTicks%3CT%3E max(int
+(double) min;%0A        return this;%0A    %7D%0A%0A    /**%0A     * User defined minimum number for the scale, overrides minimum value from data.%0A     */%0A    public LinearTicks%3CT%3E min(double min) %7B%0A        this.min = min;%0A        return this;%0A    %7D%0A%0A    /**%0A     * User defined maximum number for the scale, overrides maximum value from data.%0A     */%0A    public LinearTicks%3CT%3E max(int max) %7B%0A        this.max = (double) max;%0A        return this;%0A    %7D%0A%0A    /**%0A     * User defined maximum number for the scale, overrides maximum value from data.%0A     */%0A    public LinearTicks%3CT%3E max(double
  max
@@ -2805,24 +2805,305 @@
 estedMax) %7B%0A
+        this.suggestedMax = (double) suggestedMax;%0A        return this;%0A    %7D%0A%0A    /**%0A     * User defined maximum number for the scale, overrides maximum value except for if it is lower than the maximum value.%0A     */%0A    public LinearTicks%3CT%3E suggestedMax(double suggestedMax) %7B%0A
         this
@@ -3387,16 +3387,25 @@
 tedMin =
+ (double)
  suggest
@@ -3439,16 +3439,288 @@
 %0A    %7D%0A%0A
+    /**%0A     * User defined minimum number for the scale, overrides minimum value except for if it is higher than the minimum value.%0A     */%0A    public LinearTicks%3CT%3E suggestedMin(double suggestedMin) %7B%0A        this.suggestedMin = suggestedMin;%0A        return this;%0A    %7D%0A
 %0A    @Ov

change type of min,max,suggestedMin and suggestedMax to Double (#82)