// SPDX-License-Identifier: GPL-3.0-or-later

// This file is auto-generated by scripts/generate_nymea_api.py
// Any changes made here will be lost when the files are regenerated.
// Do not edit manually.

#include "zwavegetnodesresponse.h"

namespace nymea::api {

ZWaveGetNodesResponse ZWaveGetNodesResponse::fromJson(const QJsonObject &object) {
    ZWaveGetNodesResponse value;
    if (object.contains(QStringLiteral("nodes"))) {
        value.nodes = ([&]() { QList<ZWaveNode> list; for (const QJsonValue &item : (object.value(QStringLiteral("nodes"))).toArray()) { list.append(ZWaveNode::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("zwaveError"))) {
        value.zwaveError = parseZWaveError(object.value(QStringLiteral("zwaveError")));
    }
    return value;
}

QJsonObject ZWaveGetNodesResponse::toJson() const {
    QJsonObject object;
    if (nodes.has_value()) {
        object.insert(QStringLiteral("nodes"), ([&]() { QJsonArray array; for (const auto &item : *nodes) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    }
    object.insert(QStringLiteral("zwaveError"), QJsonValue(toString(zwaveError)));
    return object;
}

} // namespace nymea::api
