package dji.v5.ux.core.base.charts.model;

import android.graphics.Typeface;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import dji.v5.ux.core.base.charts.formatter.AxisValueFormatter;
import dji.v5.ux.core.base.charts.formatter.SimpleAxisValueFormatter;
import dji.v5.ux.core.base.charts.util.ChartUtils;

public class Axis {
    private int textSize = 12;
    private int maxLabelChars = 3;
    private List<AxisValue> values = new ArrayList<>();
    private String name;
    private boolean isAutoGenerated = true;
    private boolean hasLines = false;
    private boolean isInside = false;
    private int textColor = -3355444;
    private int lineColor;
    private Typeface typeface;
    private AxisValueFormatter formatter;
    private boolean hasSeparationLine;
    private boolean hasTiltedLabels;

    public Axis() {
        this.lineColor = ChartUtils.DEFAULT_DARKEN_COLOR;
        this.formatter = new SimpleAxisValueFormatter();
        this.hasSeparationLine = true;
        this.hasTiltedLabels = false;
    }

    public Axis(List<AxisValue> values) {
        this.lineColor = ChartUtils.DEFAULT_DARKEN_COLOR;
        this.formatter = new SimpleAxisValueFormatter();
        this.hasSeparationLine = true;
        this.hasTiltedLabels = false;
        this.setValues(values);
    }

    public Axis(Axis axis) {
        this.lineColor = ChartUtils.DEFAULT_DARKEN_COLOR;
        this.formatter = new SimpleAxisValueFormatter();
        this.hasSeparationLine = true;
        this.hasTiltedLabels = false;
        this.name = axis.name;
        this.isAutoGenerated = axis.isAutoGenerated;
        this.hasLines = axis.hasLines;
        this.isInside = axis.isInside;
        this.textColor = axis.textColor;
        this.lineColor = axis.lineColor;
        this.textSize = axis.textSize;
        this.maxLabelChars = axis.maxLabelChars;
        this.typeface = axis.typeface;
        this.formatter = axis.formatter;
        this.hasSeparationLine = axis.hasSeparationLine;
        Iterator<AxisValue> var2 = axis.values.iterator();

        while(var2.hasNext()) {
            AxisValue axisValue = (AxisValue)var2.next();
            this.values.add(new AxisValue(axisValue));
        }

    }

    public static Axis generateAxisFromRange(float start, float stop, float step) {
        List<AxisValue> values = new ArrayList<>();

        for(float value = start; value <= stop; value += step) {
            AxisValue axisValue = new AxisValue(value);
            values.add(axisValue);
        }

        return new Axis(values);
    }

    public static Axis generateAxisFromCollection(List<Float> axisValues) {
        List<AxisValue> values = new ArrayList<>();
        int index = 0;

        for(Iterator<Float> var3 = axisValues.iterator(); var3.hasNext(); ++index) {
            float value = (Float)var3.next();
            AxisValue axisValue = new AxisValue(value);
            values.add(axisValue);
        }

        return new Axis(values);
    }

    public static Axis generateAxisFromCollection(List<Float> axisValues, List<String> axisValuesLabels) {
        if (axisValues.size() != axisValuesLabels.size()) {
            throw new IllegalArgumentException("Values and labels lists must have the same size!");
        } else {
            List<AxisValue> values = new ArrayList<>();
            int index = 0;

            for(Iterator<Float> var4 = axisValues.iterator(); var4.hasNext(); ++index) {
                float value = (Float)var4.next();
                AxisValue axisValue = (new AxisValue(value)).setLabel((String)axisValuesLabels.get(index));
                values.add(axisValue);
            }

            return new Axis(values);
        }
    }

    public List<AxisValue> getValues() {
        return this.values;
    }

    public Axis setValues(List<AxisValue> values) {
        if (null == values) {
            this.values = new ArrayList<>();
        } else {
            this.values = values;
        }

        this.isAutoGenerated = false;
        return this;
    }

    public String getName() {
        return this.name;
    }

    public Axis setName(String name) {
        this.name = name;
        return this;
    }

    public boolean isAutoGenerated() {
        return this.isAutoGenerated;
    }

    public Axis setAutoGenerated(boolean isAutoGenerated) {
        this.isAutoGenerated = isAutoGenerated;
        return this;
    }

    public boolean hasLines() {
        return this.hasLines;
    }

    public Axis setHasLines(boolean hasLines) {
        this.hasLines = hasLines;
        return this;
    }

    public int getTextColor() {
        return this.textColor;
    }

    public Axis setTextColor(int color) {
        this.textColor = color;
        return this;
    }

    public boolean isInside() {
        return this.isInside;
    }

    public Axis setInside(boolean isInside) {
        this.isInside = isInside;
        return this;
    }

    public int getLineColor() {
        return this.lineColor;
    }

    public Axis setLineColor(int lineColor) {
        this.lineColor = lineColor;
        return this;
    }

    public int getTextSize() {
        return this.textSize;
    }

    public Axis setTextSize(int textSize) {
        this.textSize = textSize;
        return this;
    }

    public int getMaxLabelChars() {
        return this.maxLabelChars;
    }

    public Axis setMaxLabelChars(int maxLabelChars) {
        if (maxLabelChars < 0) {
            maxLabelChars = 0;
        } else if (maxLabelChars > 32) {
            maxLabelChars = 32;
        }

        this.maxLabelChars = maxLabelChars;
        return this;
    }

    public Typeface getTypeface() {
        return this.typeface;
    }

    public Axis setTypeface(Typeface typeface) {
        this.typeface = typeface;
        return this;
    }

    public AxisValueFormatter getFormatter() {
        return this.formatter;
    }

    public Axis setFormatter(AxisValueFormatter formatter) {
        if (null == formatter) {
            this.formatter = new SimpleAxisValueFormatter();
        } else {
            this.formatter = formatter;
        }

        return this;
    }

    public Axis setHasSeparationLine(boolean hasSeparationLine) {
        this.hasSeparationLine = hasSeparationLine;
        return this;
    }

    public boolean hasSeparationLine() {
        return this.hasSeparationLine;
    }

    public boolean hasTiltedLabels() {
        return this.hasTiltedLabels;
    }

    public Axis setHasTiltedLabels(boolean hasTiltedLabels) {
        this.hasTiltedLabels = hasTiltedLabels;
        return this;
    }
}

