package io.github.jjsimas.chart2d;

public final class PieChartOptions {

  private final LegendPosition legendPosition;
  private final boolean showLegend;
  private final boolean showTitle;
  private final boolean showLabels;
  private final int preferredDiameterModel;

  private PieChartOptions(Builder builder) {
    legendPosition = builder.legendPosition;
    showLegend = builder.showLegend;
    showTitle = builder.showTitle;
    showLabels = builder.showLabels;
    preferredDiameterModel = builder.preferredDiameterModel;
  }

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

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

  public LegendPosition legendPosition() {
    return legendPosition;
  }

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

  public boolean showTitle() {
    return showTitle;
  }

  public boolean showLabels() {
    return showLabels;
  }

  public int preferredDiameterModel() {
    return preferredDiameterModel;
  }

  public static final class Builder {

    private LegendPosition legendPosition = LegendPosition.RIGHT;
    private boolean showLegend = true;
    private boolean showTitle = true;
    private boolean showLabels = true;
    private int preferredDiameterModel = 260;

    private Builder() {
    }

    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 showLabels(boolean value) {
      showLabels = value;
      return this;
    }

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

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