package io.github.jjsimas.chart2d;

public final class CartesianChartOptions {

  private final CartesianOrientation orientation;
  private final LegendPosition legendPosition;
  private final boolean showLegend;
  private final boolean showTitle;
  private final boolean showAxisTitles;
  private final boolean showGrid;
  private final boolean showCategoryAxis;
  private final boolean showValueAxis;
  private final boolean stackedBars;
  private final boolean clipPlot;
  private final int valueTickCountHint;
  private final int preferredCategorySpanModel;

  private CartesianChartOptions(Builder builder) {
    orientation = builder.orientation;
    legendPosition = builder.legendPosition;
    showLegend = builder.showLegend;
    showTitle = builder.showTitle;
    showAxisTitles = builder.showAxisTitles;
    showGrid = builder.showGrid;
    showCategoryAxis = builder.showCategoryAxis;
    showValueAxis = builder.showValueAxis;
    stackedBars = builder.stackedBars;
    clipPlot = builder.clipPlot;
    valueTickCountHint = builder.valueTickCountHint;
    preferredCategorySpanModel = builder.preferredCategorySpanModel;
  }

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

  public static CartesianChartOptions defaults() {
    return builder().build();
  }

  public CartesianOrientation orientation() {
    return orientation;
  }

  public LegendPosition legendPosition() {
    return legendPosition;
  }

  public boolean showLegend() {
    return showLegend && legendPosition != LegendPosition.NONE;
  }

  public boolean showTitle() {
    return showTitle;
  }

  public boolean showAxisTitles() {
    return showAxisTitles;
  }

  public boolean showGrid() {
    return showGrid;
  }

  public boolean showCategoryAxis() {
    return showCategoryAxis;
  }

  public boolean showValueAxis() {
    return showValueAxis;
  }

  public boolean stackedBars() {
    return stackedBars;
  }

  public boolean clipPlot() {
    return clipPlot;
  }

  public int valueTickCountHint() {
    return valueTickCountHint;
  }

  public int preferredCategorySpanModel() {
    return preferredCategorySpanModel;
  }

  public static final class Builder {

    private CartesianOrientation orientation = CartesianOrientation.VERTICAL;
    private LegendPosition legendPosition = LegendPosition.RIGHT;
    private boolean showLegend = true;
    private boolean showTitle = true;
    private boolean showAxisTitles = true;
    private boolean showGrid = true;
    private boolean showCategoryAxis = true;
    private boolean showValueAxis = true;
    private boolean stackedBars = false;
    private boolean clipPlot = true;
    private int valueTickCountHint = 6;
    private int preferredCategorySpanModel = 36;

    private Builder() {
    }

    public Builder orientation(CartesianOrientation value) {
      orientation = value;
      return this;
    }

    public Builder legendPosition(LegendPosition value) {
      legendPosition = value;
      return this;
    }

    public Builder showLegend(boolean value) {
      showLegend = value;
      return this;
    }

    public Builder showTitle(boolean value) {
      showTitle = value;
      return this;
    }

    public Builder showAxisTitles(boolean value) {
      showAxisTitles = value;
      return this;
    }

    public Builder showGrid(boolean value) {
      showGrid = value;
      return this;
    }

    public Builder showCategoryAxis(boolean value) {
      showCategoryAxis = value;
      return this;
    }

    public Builder showValueAxis(boolean value) {
      showValueAxis = value;
      return this;
    }

    public Builder stackedBars(boolean value) {
      stackedBars = value;
      return this;
    }

    public Builder clipPlot(boolean value) {
      clipPlot = value;
      return this;
    }

    public Builder valueTickCountHint(int value) {
      valueTickCountHint = Math.max(2, value);
      return this;
    }

    public Builder preferredCategorySpanModel(int value) {
      preferredCategorySpanModel = Math.max(12, value);
      return this;
    }

    public CartesianChartOptions build() {
      return new CartesianChartOptions(this);
    }
  }
}
