package jtznyj.engineer.service.winform.data;

import org.jeecg.common.util.DateUtils;
import jtznyj.engineer.service.dataDiagnosticService.data.AnalyseType;

import java.text.DecimalFormat;
import java.util.Date;

public class SecondState {
    public AnalyseType _analyseType = AnalyseType.AT_NULL;

    private String _name = "";

    public int _count = 0;

    private Date _dtStartTime;

    private Date _dtEndTime;

    public double _value0;

    public double _value1;

    public double _valueMin;

    public double _valueMax;

    public boolean _bAlarm = false;

    public SecondState Clone() {
        SecondState result = new SecondState(String.valueOf(this._name));
        result._analyseType = this._analyseType;
        result._count = this._count;
        result._dtStartTime = this._dtStartTime;
        result._dtEndTime = this._dtEndTime;
        result._value0 = this._value0;
        result._value1 = this._value1;
        result._valueMin = this._valueMin;
        result._valueMax = this._valueMax;
        result._bAlarm = this._bAlarm;

        return result;
    }

    public SecondState(String name) {
        this._name = name;
    }

    public void SetRange(Date dtStartTime, Date dtEndTime, int count) {
        this._count = count;
        this._analyseType = AnalyseType.AT_Range;
        this._dtStartTime = dtStartTime;
        this._dtEndTime = dtEndTime;
    }

    public void BdRange(Date dtStartTime, Date dtEndTime, double value0) {
        this._analyseType = AnalyseType.AT_BdRange;
        this._dtStartTime = dtStartTime;
        this._dtEndTime = dtEndTime;
        this._value0 = value0;
    }


    public void SetMinMax(Date dtStartTime, Date dtEndTime, double minv, double maxv, double value0) {
        this._value0 = value0;
        this._analyseType = AnalyseType.AT_MinMax;
        this._dtStartTime = dtStartTime;
        this._dtEndTime = dtEndTime;
        this._valueMin = minv;
        this._valueMax = maxv;
    }

    public void SetTrend(Date dtStartTime, Date dtEndTime, double value0, double value1) {
        this._value0 = value0;
        this._value1 = value1;
        this._analyseType = AnalyseType.AT_Trend;
        this._dtStartTime = dtStartTime;
        this._dtEndTime = dtEndTime;
    }

    public void SetAlarm(boolean bAlram) {
        this._bAlarm = bAlram;
    }

    public String GetSecondDescription() {
        String info = "";
        DecimalFormat df = new DecimalFormat("0.0000");
        DecimalFormat valueDf = new DecimalFormat("0.00");

        DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
        switch (this._analyseType) {
            case AT_MinMax:
                if (!this._bAlarm) {
                    info = String.format("%s 值正常", this._name);
                } else {

//                    info = String.format("%6$s %1$s 至%2$s 超出正常范围[%3$s-%4$s]，当前值%5$s",
//                            DateUtils.formatDate(this._dtStartTime, "HH:mm:ss"),
//                            DateUtils.formatDate(this._dtEndTime, "HH:mm:ss"),
//                            decimalFormat.format(this._valueMin),
//                            decimalFormat.format(this._valueMax),
//                            valueDf.format(this._value0),
//                            this._name);
                            info = String.format("%3$s %1$s 至%2$s",
                            DateUtils.formatDate(this._dtStartTime, "HH:mm:ss"),
                            DateUtils.formatDate(this._dtEndTime, "HH:mm:ss"),
                            this._name);
                }
                break;
            case AT_Range:
                if (!this._bAlarm) {
                    info = String.format("%s 值正常", this._name);
                } else {
//                    info = String.format("%3$s %1$s 至%2$s 出现次数%4$s",
//                            DateUtils.formatDate(this._dtStartTime, "HH:mm:ss"),
//                            DateUtils.formatDate(this._dtEndTime, "HH:mm:ss"),
//                            this._name,
//                            this._count);

                    info = String.format("%3$s %1$s 至%2$s",
                            DateUtils.formatDate(this._dtStartTime, "HH:mm:ss"),
                            DateUtils.formatDate(this._dtEndTime, "HH:mm:ss"),
                            this._name);
                }
                break;
            case AT_BdRange:
                if (!this._bAlarm) {
                    info = String.format("%s 值正常", this._name);
                } else {
                    info = String.format("%3$s %1$s 至%2$s ",
                            DateUtils.formatDate(this._dtStartTime, "HH:mm:ss"),
                            DateUtils.formatDate(this._dtEndTime, "HH:mm:ss"),
                            this._name);
                }
                break;
            case AT_Trend:
                if (!this._bAlarm) {
                    info = String.format("%s 值正常", this._name);
                } else {
                    String dir = "↓";
                    if (this._value0 < this._value1) {
                        dir = "↑";
                    }
                    info = String.format("%3$s %1$s 至%2$s",
                            DateUtils.formatDate(this._dtStartTime, "HH:mm:ss"),
                            DateUtils.formatDate(this._dtEndTime, "HH:mm:ss"),
                            this._name
                    );
                }
                break;
        }
        return info;
    }
}
