// 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 "zigbeenodeendpoint.h"

namespace nymea::api {

ZigbeeNodeEndpoint ZigbeeNodeEndpoint::fromJson(const QJsonObject &object) {
    ZigbeeNodeEndpoint value;
    if (object.contains(QStringLiteral("endpointId"))) {
        value.endpointId = jsonValueToUnsignedInteger(object.value(QStringLiteral("endpointId")));
    }
    if (object.contains(QStringLiteral("inputClusters"))) {
        value.inputClusters = ([&]() { QList<ZigbeeCluster> list; for (const QJsonValue &item : (object.value(QStringLiteral("inputClusters"))).toArray()) { list.append(ZigbeeCluster::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("outputClusters"))) {
        value.outputClusters = ([&]() { QList<ZigbeeCluster> list; for (const QJsonValue &item : (object.value(QStringLiteral("outputClusters"))).toArray()) { list.append(ZigbeeCluster::fromJson((item).toObject())); } return list; }());
    }
    return value;
}

QJsonObject ZigbeeNodeEndpoint::toJson() const {
    QJsonObject object;
    object.insert(QStringLiteral("endpointId"), QJsonValue(static_cast<qint64>(endpointId)));
    object.insert(QStringLiteral("inputClusters"), ([&]() { QJsonArray array; for (const auto &item : inputClusters) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("outputClusters"), ([&]() { QJsonArray array; for (const auto &item : outputClusters) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    return object;
}

} // namespace nymea::api
