package http.vo.response;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

/**
 * info
 *
 * @author ReiChin_
 */
public class LabWarnVo {

    public String eventId;
    public String eventName;
    public String subName;
    public String riskPlanId;
    public String riskPlanName;
    public String riskPlanLevel;
    public String riskReason;
    public boolean ifCheck;
    public String eventStartTime;
    public String riskAttribute;
    public String triggerUploadData;
    public String buildId;
    public String floorId;
    public String subId;
    public String infoId;
    public String eventStartTimestamp;

    public List<TriggerVo> triggerList;

    public TriggerVo firstTrigger() {
        if (null != triggerList && !triggerList.isEmpty()) {
            return triggerList.get(0);
        }

        try {
            if (null != triggerUploadData && triggerUploadData.length() > 0) {
                Type typeOfT = new TypeToken<List<TriggerVo>>() {}.getType();
                triggerList = new Gson().fromJson(triggerUploadData, typeOfT);

                if (null != triggerList && !triggerList.isEmpty()) {
                    return triggerList.get(0);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static class TriggerVo {

        public String code; // 设备Code
        public String deviceId; // 设备ID
        public String deviceName; // 设备名称
        public String deviceNo; // 设备号
        public String deviceValue; // 设备读数
        public String lastOnlineTime; // 最后一次在线时间
        public boolean online; // 是否在线
        public String unit; // 功能值单位

        public String formatWaring() {
            String describe_ = null == deviceName ? "" : deviceName;
            String val_ = null == deviceValue ? "" : deviceValue;
            String unit_ = null == unit ? "" : unit;
            return String.format("%s：%s%s", describe_, val_, unit_);
        }
    }

}
