package jtznyj.engineer.service.winform.data;

import cn.hutool.core.date.DateUtil;

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

/**
 * 监控预警记录
 */
public class MonitorAlarmRecord {
    public String _name;

    /**
     * 首次预报时间
     */
    public Date _dtFirstForcast;

    /**
     * 开始时间
     */
    public Date _dtStart;

    /**
     * 类型
     */
    public String _lx;

    /**
     * 截止时间
     */
    public Date _dtEnd;

    public double _realDepthStart = 0.0;

    public double _realDepthEnd = 0.0;

    public double _bitDepthStart = 0.0;

    public double _bitDepthEnd = 0.0;

    public boolean _isNeedUpdate = false;

    public String warnMsg = "";

    public ArrayList<MonitorDescription> _listMds;

    public SecondStates _secondStates = new SecondStates();

    public MonitorAlarmRecord(String name, Date dtStart, Date dtEnd, ArrayList<MonitorDescription> listMds) {
        this._name = name;
        this._dtStart = dtStart;
        this._dtEnd = dtEnd;
        this._listMds = listMds;
        this._realDepthStart = this._listMds.get(0)._startDepth;
        this._realDepthEnd = this._listMds.get(0)._endDepth;
        this._bitDepthStart = this._listMds.get(0)._startZtDepth;
        this._bitDepthEnd = this._listMds.get(0)._endZtDepth;
        this._lx = this._listMds.get(0).lx;
    }

    public boolean Compare(MonitorAlarmRecord mar) {
        return mar._name == this._name && mar._dtStart == this._dtStart;
    }

    public MonitorAlarmRecord Clone() {
        ArrayList<MonitorDescription> newListMds = new ArrayList<MonitorDescription>();

        _listMds.forEach((md) -> {
            newListMds.add((MonitorDescription) md.Clone());
        });
        MonitorAlarmRecord result = new MonitorAlarmRecord(String.valueOf(this._name), this._dtStart, this._dtEnd, newListMds);

        result._realDepthStart = this._realDepthStart;
        result._realDepthEnd = this._realDepthEnd;
        result._bitDepthStart = this._bitDepthStart;
        result._bitDepthEnd = this._bitDepthEnd;
        return result;
    }

    public void SetAlarmMsg(int index, String jh) {

        DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("[ %s %s ]",  jh, _name));
        sb.append("<br/>");
        sb.append(String.format("时间：%s 至 %s", DateUtil.format(_dtStart,"yyyy-MM-dd HH:mm:ss"),DateUtil.format(_dtEnd,"yyyy-MM-dd HH:mm:ss")));
        sb.append("<br/>");
        sb.append(String.format("深度段:%s～%sm", decimalFormat.format(_realDepthStart), decimalFormat.format(_realDepthEnd)));
        sb.append("<br/>");
        sb.append(String.format("异常原因:%s", _secondStates.GetDescription()));
//        sb.append("<br/>");
        sb.append(this._lx);
        sb.append("<br/>");
        this.warnMsg = sb.toString();
    }
}
