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

namespace nymea::api {

ZigbeeNode ZigbeeNode::fromJson(const QJsonObject &object) {
    ZigbeeNode value;
    if (object.contains(QStringLiteral("bindingTableRecords"))) {
        value.bindingTableRecords = ([&]() { QList<ZigbeeBindingTableRecord> list; for (const QJsonValue &item : (object.value(QStringLiteral("bindingTableRecords"))).toArray()) { list.append(ZigbeeBindingTableRecord::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("endpoints"))) {
        value.endpoints = ([&]() { QList<ZigbeeNodeEndpoint> list; for (const QJsonValue &item : (object.value(QStringLiteral("endpoints"))).toArray()) { list.append(ZigbeeNodeEndpoint::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("ieeeAddress"))) {
        value.ieeeAddress = (object.value(QStringLiteral("ieeeAddress"))).toString();
    }
    if (object.contains(QStringLiteral("lastSeen"))) {
        value.lastSeen = jsonValueToUnsignedInteger(object.value(QStringLiteral("lastSeen")));
    }
    if (object.contains(QStringLiteral("lqi"))) {
        value.lqi = jsonValueToUnsignedInteger(object.value(QStringLiteral("lqi")));
    }
    if (object.contains(QStringLiteral("manufacturer"))) {
        value.manufacturer = (object.value(QStringLiteral("manufacturer"))).toString();
    }
    if (object.contains(QStringLiteral("model"))) {
        value.model = (object.value(QStringLiteral("model"))).toString();
    }
    if (object.contains(QStringLiteral("neighborTableRecords"))) {
        value.neighborTableRecords = ([&]() { QList<ZigbeeNeighborTableRecord> list; for (const QJsonValue &item : (object.value(QStringLiteral("neighborTableRecords"))).toArray()) { list.append(ZigbeeNeighborTableRecord::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("networkAddress"))) {
        value.networkAddress = jsonValueToUnsignedInteger(object.value(QStringLiteral("networkAddress")));
    }
    if (object.contains(QStringLiteral("networkUuid"))) {
        value.networkUuid = QUuid((object.value(QStringLiteral("networkUuid"))).toString());
    }
    if (object.contains(QStringLiteral("reachable"))) {
        value.reachable = (object.value(QStringLiteral("reachable"))).toBool();
    }
    if (object.contains(QStringLiteral("receiverOnWhileIdle"))) {
        value.receiverOnWhileIdle = (object.value(QStringLiteral("receiverOnWhileIdle"))).toBool();
    }
    if (object.contains(QStringLiteral("routingTableRecords"))) {
        value.routingTableRecords = ([&]() { QList<ZigbeeRoutingTableRecord> list; for (const QJsonValue &item : (object.value(QStringLiteral("routingTableRecords"))).toArray()) { list.append(ZigbeeRoutingTableRecord::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("state"))) {
        value.state = parseZigbeeNodeState(object.value(QStringLiteral("state")));
    }
    if (object.contains(QStringLiteral("type"))) {
        value.type = parseZigbeeNodeType(object.value(QStringLiteral("type")));
    }
    if (object.contains(QStringLiteral("version"))) {
        value.version = (object.value(QStringLiteral("version"))).toString();
    }
    return value;
}

QJsonObject ZigbeeNode::toJson() const {
    QJsonObject object;
    object.insert(QStringLiteral("bindingTableRecords"), ([&]() { QJsonArray array; for (const auto &item : bindingTableRecords) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("endpoints"), ([&]() { QJsonArray array; for (const auto &item : endpoints) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("ieeeAddress"), QJsonValue(ieeeAddress));
    object.insert(QStringLiteral("lastSeen"), QJsonValue(static_cast<qint64>(lastSeen)));
    object.insert(QStringLiteral("lqi"), QJsonValue(static_cast<qint64>(lqi)));
    object.insert(QStringLiteral("manufacturer"), QJsonValue(manufacturer));
    object.insert(QStringLiteral("model"), QJsonValue(model));
    object.insert(QStringLiteral("neighborTableRecords"), ([&]() { QJsonArray array; for (const auto &item : neighborTableRecords) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("networkAddress"), QJsonValue(static_cast<qint64>(networkAddress)));
    object.insert(QStringLiteral("networkUuid"), QJsonValue((networkUuid).toString()));
    object.insert(QStringLiteral("reachable"), QJsonValue(reachable));
    object.insert(QStringLiteral("receiverOnWhileIdle"), QJsonValue(receiverOnWhileIdle));
    object.insert(QStringLiteral("routingTableRecords"), ([&]() { QJsonArray array; for (const auto &item : routingTableRecords) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("state"), QJsonValue(toString(state)));
    object.insert(QStringLiteral("type"), QJsonValue(toString(type)));
    object.insert(QStringLiteral("version"), QJsonValue(version));
    return object;
}

} // namespace nymea::api
