package com.ruoyi.system.core.mqtt;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.system.core.DeviceStatus;
import com.ruoyi.system.domain.SysDevice;
import com.ruoyi.system.domain.SysDeviceProperty;
import com.ruoyi.system.domain.SysDeviceStatus;

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

public class ReplyPackage {
    private String deviceId;

    private String inputs;

    private String messageId;

    public ReplyPackage(SysDeviceStatus status, DefProtocol defProtocol) {
        JSONArray objects = JSON.parseArray(status.getInputs());
        JSONObject obj = new JSONObject();
        for (int i = 0; i < objects.size(); i++) {
            obj.put(objects.getJSONObject(i).getString("name"),objects.getJSONObject(i).getString("value"));
        }
        this.setInputs(obj.toJSONString());
        this.setMessageId(defProtocol.getMessageId());
        this.setDeviceId(defProtocol.getDeviceId());
    }

    public ReplyPackage(List<SysDeviceProperty> status, DefProtocol defProtocol) {
        JSONObject obj = new JSONObject();
        for (SysDeviceProperty sysDeviceProperty : status) {
            obj.put(sysDeviceProperty.getName(),sysDeviceProperty.getValue());
        }
        this.setInputs(obj.toJSONString());
        this.setMessageId(defProtocol.getMessageId());
        this.setDeviceId(defProtocol.getDeviceId());
    }

    public ReplyPackage() {
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getInputs() {
        return inputs;
    }

    public void setInputs(String inputs) {
        this.inputs = inputs;
    }

    public String getMessageId() {
        return messageId;
    }

    public void setMessageId(String messageId) {
        this.messageId = messageId;
    }

}
