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

namespace nymea::api {

NetworkManagerGetNetworkDevicesResponse NetworkManagerGetNetworkDevicesResponse::fromJson(const QJsonObject &object) {
    NetworkManagerGetNetworkDevicesResponse value;
    if (object.contains(QStringLiteral("networkManagerError"))) {
        value.networkManagerError = parseNetworkManagerError(object.value(QStringLiteral("networkManagerError")));
    }
    if (object.contains(QStringLiteral("wiredNetworkDevices"))) {
        value.wiredNetworkDevices = ([&]() { QList<WiredNetworkDevice> list; for (const QJsonValue &item : (object.value(QStringLiteral("wiredNetworkDevices"))).toArray()) { list.append(WiredNetworkDevice::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("wirelessNetworkDevices"))) {
        value.wirelessNetworkDevices = ([&]() { QList<WirelessNetworkDevice> list; for (const QJsonValue &item : (object.value(QStringLiteral("wirelessNetworkDevices"))).toArray()) { list.append(WirelessNetworkDevice::fromJson((item).toObject())); } return list; }());
    }
    return value;
}

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

} // namespace nymea::api
