package org.example.Entity.Control.Panel;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.example.Entity.Control.Base.RowComponent;
import org.example.Enums.SystemEnums;
import org.example.Utils.DataTableUtil;
import org.example.Utils.NativeExtensionUtils;

import java.math.BigDecimal;
import java.util.Map;
import java.util.Objects;

import static org.example.Utils.NativeExtensionUtils.ToInt32;
import static org.example.Utils.NativeExtensionUtils.toBoolean;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Chart extends RowComponent {

    public Chart(Map<String, Object> row) {
        super(row);
    }

    @Override
    public String getXtype() {
        SystemEnums.ChartType chartType;
        try {
            chartType = SystemEnums.ChartType.fromValue(getCharttype());
            switch (chartType) {
                case Line:
                case Bar:
                    return "chart.Bar";
                case Pie:
                    return "chart.Pie";
                case Funnel:
                    return "chart.Funnel";
                default:
                    return "chart.Base";
            }
        } catch (Exception e) {
            return "chart.Base";
        }
    }

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public String getSeriestype() {
        try {
            SystemEnums.ChartType chartType = SystemEnums.ChartType.fromValue(getCharttype());
            if (chartType != null) {
                return chartType.name().toLowerCase();
            }
        } catch (Exception e) {
            return null;
        }
        return null;
    }

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public Object option;

    public String _charttile;

    public String getCharttitle() {

        return (String) DataTableUtil.getRowVal(this._row, "charttitle", _charttile, null);
    }

    public void setCharttitle(String charttitle) {
        this._charttile = charttitle;
    }

    private Integer _charttype;

    @JsonIgnore
    public int getCharttype() {
        return ToInt32(DataTableUtil.getRowVal(this._row, "charttype", _charttype, 0));
    }

    public void setCharttype(int charttype) {
        this._charttype = charttype;
    }

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public String getChartcolor() {

        return (String) DataTableUtil.getRowVal(this._row, "chartcolor", null);
    }

    public void setChartcolor(String chartcolor) {
        this._chartcolordf = (chartcolor);
    }

    private String _chartcolordf;

    @JsonIgnore
    public String getChartcolordf() {

        return (String) DataTableUtil.getRowVal(this._row, "chartcolordf", _chartcolordf, null);
    }

    public void setChartcolordf(String chartcolordf) {
        this._chartcolordf = chartcolordf;
    }

    private String _xlabelfield;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public String getXlabelfield() {
        _xlabelfield = (String) DataTableUtil.getRowVal(this._row, "xlabelfield", _xlabelfield, null);
        if (_xlabelfield != null && !_xlabelfield.isEmpty()) {
            return _xlabelfield.toLowerCase();
        }
        return _xlabelfield;
    }

    public void setXlabelfield(String xlabelfield) {
        this._xlabelfield = xlabelfield;
    }

    private String _yvaluefield;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public String getYvaluefield() {
        _yvaluefield = (String) DataTableUtil.getRowVal(this._row, "yvaluefield", _yvaluefield, null);
        if (_yvaluefield != null && !_yvaluefield.isEmpty()) {
            _yvaluefield = _yvaluefield.toLowerCase();
        }
        return _yvaluefield;
    }

    public void setYvaluefield(String yvaluefield) {
        this._yvaluefield = yvaluefield;
    }

    private String _yvaluefield1;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public String getYvaluefield1() {
        _yvaluefield1 = (String) DataTableUtil.getRowVal(this._row, "yvaluefield1", _yvaluefield1, null);
        if (_yvaluefield1 != null && !_yvaluefield1.isEmpty()) {
            _yvaluefield1 = _yvaluefield1.toLowerCase();
        }
        return _yvaluefield1;
    }

    public void setYvaluefield1(String yvaluefield1) {
        this._yvaluefield1 = yvaluefield1;
    }

    private String _yvaluefield2;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public String getYvaluefield2() {
        _yvaluefield2 = (String) DataTableUtil.getRowVal(this._row, "yvaluefield2", _yvaluefield2, null);
        if (_yvaluefield2 != null && !_yvaluefield2.isEmpty()) {
            _yvaluefield2 = _yvaluefield2.toLowerCase();
        }
        return _yvaluefield2;
    }

    public void setYvaluefield2(String yvaluefield2) {
        this._yvaluefield2 = yvaluefield2;
    }


    private String _xaxistitle;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public String getXaxistitle() {

        return (String) DataTableUtil.getRowVal(this._row, "xaxistitle", _xaxistitle, null);
    }

    public void setXaxistitle(String xaxistitle) {
        this._xaxistitle = xaxistitle;
    }


    private String _yaxistitle;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public String getYaxistitle() {

        return (String) DataTableUtil.getRowVal(this._row, "yaxistitle", _yaxistitle, null);
    }

    public void setYaxistitle(String yaxistitle) {
        this._yaxistitle = yaxistitle;
    }

    private String _yaxisshared;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public String getYaxisshared() {
        Object value = DataTableUtil.getRowVal(_row, "yaxisshared", _yaxisshared);
        return value != null ? value.toString() : null;
    }

    public void setYaxisshared(String yaxisshared) {
        this._yaxisshared = yaxisshared;
    }


    private Integer _isabsolutely;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public Integer getIsabsolutely() {
        Object val = DataTableUtil.getRowVal(_row, "isabsolutely", _isabsolutely);
        return val != null ? (Integer) val : null;
    }

    public void setIsabsolutely(Integer isabsolutely) {
        this._isabsolutely = isabsolutely;
    }

    private BigDecimal _yscale;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public BigDecimal getYscale() {
        Object val = DataTableUtil.getRowVal(_row, "yscale", _yscale);
        return val != null ? (BigDecimal) val : null;
    }

    public void setYscale(BigDecimal yscale) {
        this._yscale = yscale;
    }

    private String _valueVisible;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public String getValueVisible() {
        Object value = DataTableUtil.getRowVal(_row, "valuevisible", _valueVisible);
        return value != null ? value.toString() : null;
    }

    public void setValueVisible(String valueVisible) {
        this._valueVisible = valueVisible;
    }

    private Integer _xLabelFontSize;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public Integer getXLabelFontSize() {
        if (_xLabelFontSize == null) {
            _xLabelFontSize = ToInt32(DataTableUtil.get(this._row, "xLabelFontSize", 0));
        }
        return _xLabelFontSize > 0 ? _xLabelFontSize : null;
    }

    public void setXLabelFontSize(Integer xLabelFontSize) {
        this._xLabelFontSize = xLabelFontSize;
    }

    private Integer _xLabelRotate;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public Integer getXLabelRotate() {
        if (_xLabelRotate == null) {
            _xLabelRotate = ToInt32(DataTableUtil.get(this._row, "xLabelRotate", 0));
        }
        return _xLabelRotate > 0 ? _xLabelRotate : null;
    }

    public void setXLabelRotate(Integer xLabelRotate) {
        this._xLabelRotate = xLabelRotate;
    }

    private Boolean _xLablVisibel;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public Boolean getXLablVisibel() {
        if (_xLablVisibel == null) {
            _xLablVisibel = toBoolean(DataTableUtil.get(this._row, "xLablVisibel", 0));
        }
        return _xLablVisibel != null && _xLablVisibel ? false : null;
    }

    public void setXLablVisibel(Boolean xLablVisibel) {
        this._xLablVisibel = xLablVisibel;
    }

    private Boolean _legendVisible;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public Boolean getLegendVisible() {
        if (_legendVisible == null) {
            _legendVisible = toBoolean(DataTableUtil.get(this._row, "legendvisible", 0));
        }
        return _legendVisible != null && _legendVisible ? false : null;
    }

    public void setLegendVisible(Boolean legendVisible) {
        this._legendVisible = legendVisible;
    }

    private Boolean _xLabelInterval;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public Boolean getXLabelInterval() {
        if (_xLabelInterval == null) {
            _xLabelInterval = toBoolean(DataTableUtil.get(this._row, "labelSpaced", 0));
        }
        return _xLabelInterval != null && _xLabelInterval ? _xLabelInterval : null;
    }

    public void setXLabelInterval(Boolean xLabelInterval) {
        this._xLabelInterval = xLabelInterval;
    }

    private Integer _pieRadius;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public Integer getPieRadius() {
        if (_pieRadius == null) {
            _pieRadius = ToInt32(DataTableUtil.get(this._row, "circlehollow", 0));
        }
        return _pieRadius > 0 ? _pieRadius : null;
    }

    public void setPieRadius(Integer pieRadius) {
        this._pieRadius = pieRadius;
    }

    private String _pieRoseType;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public String getPieRoseType() {
        if (_pieRoseType == null) {
            _pieRoseType = Objects.toString(DataTableUtil.get(this._row, "circlejagge", 0), "").toLowerCase();
        }
        if (_pieRoseType != null && !_pieRoseType.isEmpty()) {
            switch (_pieRoseType) {
                case "radius":
                    return "radius";
                case "area":
                    return "area";
                default:
                    return "radius";
            }
        }
        return null;
    }

    public void setPieRoseType(String pieRoseType) {
        this._pieRoseType = pieRoseType;
    }
}