#include "NtpServerStatusDto.h"

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

}


QJsonObject NtpServerStatusDto::toJSON()
{
    QJsonObject jsonObj;

    QJsonObject dataObj;
    dataObj.insert("devStatus", devStatus);
    dataObj.insert("freqInType", freqInType);
    dataObj.insert("freqInTypeStr", freqInType == "1" ? "5M" : (freqInType == "2" ? "10M" : "no signal"));
    dataObj.insert("oppsValid", oppsValid);
    dataObj.insert("bdcValid", bdcValid);
    dataObj.insert("dclsValid", dclsValid);
    dataObj.insert("dclsInType", dclsInType);
    dataObj.insert("dclsOutType", dclsOutType);
    dataObj.insert("refType", refType);
    dataObj.insert("refStatus", refStatus);
    dataObj.insert("sysTime", sysTime);

    QJsonArray outValidArray;
    for (int i = 0; i < outValid.size(); i++)
    {
        outValidArray.append(outValid.at(i));
    }
    dataObj.insert("outValid", outValidArray);

    QJsonArray tmSrcPrioArray;
    QJsonArray tmSrcPrioStrArray;
    for (int i = 0; i < tmSrcPrio.size(); i++)
    {
        tmSrcPrioArray.append(tmSrcPrio.at(i));

        QString tmSrcStr = "";
        switch (tmSrcPrio.at(i).toInt()) {
        case 0 :
            tmSrcStr = "BDC";
            break;
        case 1:
            tmSrcStr = "1PPS";
            break;
        case 2:
            tmSrcStr = "Freq(5M/10M)";
            break;
        case 3:
            tmSrcStr = "AM";
            break;
        case 4:
            tmSrcStr = "DCLS";
            break;
        }
        tmSrcPrioStrArray.append(tmSrcStr);
    }
    dataObj.insert("tmSrcPrio", tmSrcPrioArray);

    switch (dclsInType.toInt()) {
    case 0 :
        dclsInTypeStr = "IRIG-A";
        break;
    case 1:
        dclsInTypeStr = "IRIG-B";
        break;
    case 2:
        dclsInTypeStr = "IRIG-E";
        break;
    case 3:
        dclsInTypeStr = "IRIG-G";
        break;
    case 4:
        dclsInTypeStr = "IRIG-NASA36";
        break;
    case 5:
        dclsInTypeStr = "IRIG-XR3";
        break;
    case 6:
        dclsInTypeStr = "IRIG-2137";
        break;
    }

    switch(dclsOutType.toInt())
    {
    case 0 :
        dclsOutTypeStr = "IRIG-A";
        break;
    case 1:
        dclsOutTypeStr = "IRIG-B";
        break;
    case 2:
        dclsOutTypeStr = "IRIG-E";
        break;
    case 3:
        dclsOutTypeStr = "IRIG-G";
        break;
    case 4:
        dclsOutTypeStr = "IRIG-NASA36";
        break;
    case 5:
        dclsOutTypeStr = "IRIG-XR3";
        break;
    case 6:
        dclsOutTypeStr = "IRIG-2137";
        break;
    }

    switch (refType.toInt()) {
    case 0 :
        refTypeStr = "BDC";
        break;
    case 1:
        refTypeStr = "1PPS";
        break;
    case 2:
        refTypeStr = "10M/5M";
        break;
    case 3:
        refTypeStr = "IRIG-A";
        break;
    case 4:
        refTypeStr = "IRIG-B";
        break;
    case 5:
        refTypeStr = "IRIG-E";
        break;
    case 6:
        refTypeStr = "IRIG-G";
        break;
    case 7:
        refTypeStr = "IRIG-NASA36";
        break;
    case 8:
        refTypeStr = "IRIG-XR3";
        break;
    case 9:
        refTypeStr = "IRIG-2137";
        break;
    }

    switch (refStatus.toInt()) {
    case 0 :
        refStatusStr = "自由";
        break;
    case 1:
        refStatusStr = "跟踪";
        break;
    case 2:
        refStatusStr = "锁定";
        break;
    case 3:
        refStatusStr = "守时";
        break;
    case 4:
        refStatusStr = "预热";
        break;
    }

//    dataObj.insert("dclsInTypeStr", dclsInTypeStr);
//    dataObj.insert("dclsOutTypeStr", dclsOutTypeStr);
//    dataObj.insert("refTypeStr", refTypeStr);
//    dataObj.insert("refStatusStr", refStatusStr);

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

    return jsonObj;
}
