#include "TimeSwitcherStatusDto.h"

TimeSwitcherStatusDto::TimeSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent)
{

}

QJsonObject TimeSwitcherStatusDto::toJSON()
{
    QJsonObject jsonObj;

    QJsonObject dataObj;
    dataObj.insert("devStatus", devStatus);
    dataObj.insert("refSelectType", refSelectType);
    dataObj.insert("refTmSrc", refTmSrc);
    dataObj.insert("oppsPhaseAccOut", oppsPhaseAccOut);
    dataObj.insert("bacRatio", bacRatio);
    dataObj.insert("bacRange", bacRange);

    QJsonArray tmSrcStatusArray;
    QJsonArray tmSrcStatusStrArray;
    QJsonArray localTmDiffArray;
    QJsonArray delayCompensArray;
    QJsonArray oppsOutStatusArray;
    QJsonArray bdcOutStatusArray;
    QJsonArray bacOutStatusArray;
    for (int i = 0; i < 5; i++)
    {
        tmSrcStatusArray.append(tmSrcStatusList.at(i));
        QString tmSrcStatus = tmSrcStatusList.at(i);
        if (tmSrcStatus.length() == 3)
        {
            QString tmSrcStatusStr = "";
            for (int j = 0; j < 3; j++)
            {
                if (tmSrcStatus.mid(j, 1) == '1')
                {
                    tmSrcStatusStr += tmSrcStr[j] + ",";
                }
            }
            tmSrcStatusStrArray.append(tmSrcStatusStr.mid(0, tmSrcStatusStr.length() - 1));
        } else
        {
            tmSrcStatusStrArray.append("");
        }
        localTmDiffArray.append(localTmDiffList.at(i));
        delayCompensArray.append(delayCompensList.at(i));
        oppsOutStatusArray.append(oppsOutStatusList.at(i));
        bdcOutStatusArray.append(bdcOutStatusList.at(i));
        bacOutStatusArray.append(bacOutStatusList.at(i));
    }
    dataObj.insert("tmSrcStatusArray", tmSrcStatusArray);
    dataObj.insert("tmSrcStatusStrArray", tmSrcStatusStrArray);
    dataObj.insert("localTmDiffArray", localTmDiffArray);
    dataObj.insert("delayCompensArray", delayCompensArray);
    dataObj.insert("oppsOutStatusArray", oppsOutStatusArray);
    dataObj.insert("bdcOutStatusArray", bdcOutStatusArray);
    dataObj.insert("bacOutStatusArray", bacOutStatusArray);

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

    return jsonObj;
}
