#include "CounterDataDto.h"
#include "common/utils/SettingConfig.h"

CounterDataDto::CounterDataDto(QObject *parent) : QObject(parent)
{

}


QJsonObject CounterDataDto::toJSON(int i)
{
    QJsonObject jsonObj;

    QJsonObject dataObj;
    dataObj.insert("channelRefNo", this->channelRefId);
    dataObj.insert("dataValue", QString("%1").arg(this->channelDataArray.at(i)));
    dataObj.insert("rawValue", QString("%1").arg(this->channelDataArray.at(i)));
    dataObj.insert("frameId", this->frameId);

    jsonObj.insert("channelNo", (i + 1));
    jsonObj.insert("ts", this->milisecond);
    jsonObj.insert("data", dataObj);

    return jsonObj;
}

QJsonObject CounterDataDto::toStatusJSON()
{
    QJsonObject jsonObj;

    QJsonObject dataObj;
    dataObj.insert("refType", this->refType);

    QJsonArray channelActive;
    for (int i = 0; i < channelActiveArray.size(); i++)
    {
        channelActive.append(channelActiveArray.at(i));
    }
    dataObj.insert("channelActive", channelActive);
    dataObj.insert("devStatus", "1");

    jsonObj.insert("data", dataObj);
    jsonObj.insert("ts", this->milisecond);
    jsonObj.insert("frameType", "0101");

    return jsonObj;
}

void CounterDataDto::clone(CounterDataDto *copy)
{
    copy->frameId = this->frameId;
    copy->channelRefId = this->channelRefId;

    copy->rawFrame = this->rawFrame;

    copy->timestamp = this->timestamp;
    copy->milisecond = this->milisecond;
    copy->devCode = this->devCode;
    copy->devStatus = this->devStatus;
}
