/*
 * Copyright Terracotta, Inc.
 *
 * Licensed 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 org.terracotta.management.registry.collect;

import org.terracotta.management.model.Objects;

import java.io.Serializable;
import java.util.concurrent.TimeUnit;

public class StatisticConfiguration implements Serializable {

  private static final long serialVersionUID = 1L;

  private long averageWindowDuration = 60;
  private TimeUnit averageWindowUnit = TimeUnit.SECONDS;
  private int historySize = 100;
  private long historyInterval = 1;
  private TimeUnit historyIntervalUnit = TimeUnit.SECONDS;
  private long timeToDisable = 30;
  private TimeUnit timeToDisableUnit = TimeUnit.SECONDS;

  public StatisticConfiguration() {
  }

  public StatisticConfiguration(long averageWindowDuration, TimeUnit averageWindowUnit, int historySize, long historyInterval, TimeUnit historyIntervalUnit, long timeToDisable, TimeUnit timeToDisableUnit) {
    this.averageWindowDuration = averageWindowDuration;
    this.averageWindowUnit = Objects.requireNonNull(averageWindowUnit);
    this.historySize = historySize;
    this.historyInterval = historyInterval;
    this.historyIntervalUnit = Objects.requireNonNull(historyIntervalUnit);
    this.timeToDisable = timeToDisable;
    this.timeToDisableUnit = Objects.requireNonNull(timeToDisableUnit);
  }

  public long averageWindowDuration() {
    return averageWindowDuration;
  }

  public TimeUnit averageWindowUnit() {
    return averageWindowUnit;
  }

  public int historySize() {
    return historySize;
  }

  public long historyInterval() {
    return historyInterval;
  }

  public TimeUnit historyIntervalUnit() {
    return historyIntervalUnit;
  }

  public long timeToDisable() {
    return timeToDisable;
  }

  public TimeUnit timeToDisableUnit() {
    return timeToDisableUnit;
  }


  @Override
  public String toString() {
    return "{averageWindowDuration=" + averageWindowDuration() +
        ", averageWindowUnit=" + averageWindowUnit() +
        ", historyInterval=" + historyInterval() +
        ", historyIntervalUnit=" + historyIntervalUnit() +
        ", historySize=" + historySize() +
        ", timeToDisable=" + timeToDisable() +
        ", timeToDisableUnit=" + timeToDisableUnit() +
        '}';
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    StatisticConfiguration that = (StatisticConfiguration) o;
    if (averageWindowDuration != that.averageWindowDuration) return false;
    if (historySize != that.historySize) return false;
    if (historyInterval != that.historyInterval) return false;
    if (timeToDisable != that.timeToDisable) return false;
    if (averageWindowUnit != that.averageWindowUnit) return false;
    if (historyIntervalUnit != that.historyIntervalUnit) return false;
    return timeToDisableUnit == that.timeToDisableUnit;
  }

  @Override
  public int hashCode() {
    int result = (int) (averageWindowDuration ^ (averageWindowDuration >>> 32));
    result = 31 * result + averageWindowUnit.hashCode();
    result = 31 * result + historySize;
    result = 31 * result + (int) (historyInterval ^ (historyInterval >>> 32));
    result = 31 * result + historyIntervalUnit.hashCode();
    result = 31 * result + (int) (timeToDisable ^ (timeToDisable >>> 32));
    result = 31 * result + timeToDisableUnit.hashCode();
    return result;
  }

  public StatisticConfiguration setAverageWindowDuration(long averageWindowDuration, TimeUnit averageWindowUnit) {
    this.averageWindowDuration = averageWindowDuration;
    this.averageWindowUnit = averageWindowUnit;
    return this;
  }

  public StatisticConfiguration setHistoryInterval(long historyInterval, TimeUnit historyIntervalUnit) {
    this.historyInterval = historyInterval;
    this.historyIntervalUnit = historyIntervalUnit;
    return this;
  }

  public StatisticConfiguration setHistorySize(int historySize) {
    this.historySize = historySize;
    return this;
  }

  public StatisticConfiguration setTimeToDisable(long timeToDisable, TimeUnit timeToDisableUnit) {
    this.timeToDisable = timeToDisable;
    this.timeToDisableUnit = timeToDisableUnit;
    return this;
  }

}

@@ -913,13 +913,8 @@
 tion
- = 60
 ;%0A  
@@ -947,35 +947,16 @@
 ndowUnit
- = TimeUnit.SECONDS
 ;%0A  priv
@@ -978,14 +978,8 @@
 Size
- = 100
 ;%0A  
@@ -1006,20 +1006,16 @@
 Interval
- = 1
 ;%0A  priv
@@ -1046,35 +1046,16 @@
 rvalUnit
- = TimeUnit.SECONDS
 ;%0A  priv
@@ -1080,13 +1080,8 @@
 able
- = 30
 ;%0A  
@@ -1118,65 +1118,362 @@
 Unit
- = TimeUnit.SECONDS;%0A%0A  public StatisticConfiguration() %7B
+;%0A%0A  /**%0A   * Initialize with default values%0A   * %3Cul%3E%0A   *   %3Cli%3EaverageWindowDuration: 60 seconds%3C/li%3E%0A   *   %3Cli%3EhistorySize: 100%3C/li%3E%0A   *   %3Cli%3EhistoryInterval: 1 second%3C/li%3E%0A   *   %3Cli%3EtimeToDisable: 30 seconds%3C/li%3E%0A   * %3C/ul%3E%0A   */%0A  public StatisticConfiguration() %7B%0A    this(60, TimeUnit.SECONDS, 100, 1, TimeUnit.SECONDS, 30, TimeUnit.SECONDS);
 %0A  %7D

Set defaults only for default constructor