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

namespace nymea::api {

WirelessNetworkDevice WirelessNetworkDevice::fromJson(const QJsonObject &object) {
    WirelessNetworkDevice value;
    if (object.contains(QStringLiteral("bitRate"))) {
        value.bitRate = (object.value(QStringLiteral("bitRate"))).toString();
    }
    if (object.contains(QStringLiteral("capabilities"))) {
        value.capabilities = ([&]() { QList<WirelessCapability> list; for (const QJsonValue &item : (object.value(QStringLiteral("capabilities"))).toArray()) { list.append(parseWirelessCapability(item)); } return list; }());
    }
    if (object.contains(QStringLiteral("interface"))) {
        value.interface = (object.value(QStringLiteral("interface"))).toString();
    }
    if (object.contains(QStringLiteral("ipv4Addresses"))) {
        value.ipv4Addresses = ([&]() { QStringList list; for (const QJsonValue &item : (object.value(QStringLiteral("ipv4Addresses"))).toArray()) { list.append(item.toString()); } return list; }());
    }
    if (object.contains(QStringLiteral("ipv6Addresses"))) {
        value.ipv6Addresses = ([&]() { QStringList list; for (const QJsonValue &item : (object.value(QStringLiteral("ipv6Addresses"))).toArray()) { list.append(item.toString()); } return list; }());
    }
    if (object.contains(QStringLiteral("macAddress"))) {
        value.macAddress = (object.value(QStringLiteral("macAddress"))).toString();
    }
    if (object.contains(QStringLiteral("mode"))) {
        value.mode = parseWirelessMode(object.value(QStringLiteral("mode")));
    }
    if (object.contains(QStringLiteral("currentAccessPoint"))) {
        value.currentAccessPoint = WirelessAccessPoint::fromJson((object.value(QStringLiteral("currentAccessPoint"))).toObject());
    }
    if (object.contains(QStringLiteral("state"))) {
        value.state = parseNetworkDeviceState(object.value(QStringLiteral("state")));
    }
    return value;
}

QJsonObject WirelessNetworkDevice::toJson() const {
    QJsonObject object;
    object.insert(QStringLiteral("bitRate"), QJsonValue(bitRate));
    object.insert(QStringLiteral("capabilities"), ([&]() { QJsonArray array; for (const auto &item : capabilities) { array.append(QJsonValue(toString(item))); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("interface"), QJsonValue(interface));
    object.insert(QStringLiteral("ipv4Addresses"), ([&]() { QJsonArray array; for (const QString &item : ipv4Addresses) { array.append(item); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("ipv6Addresses"), ([&]() { QJsonArray array; for (const QString &item : ipv6Addresses) { array.append(item); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("macAddress"), QJsonValue(macAddress));
    object.insert(QStringLiteral("mode"), QJsonValue(toString(mode)));
    if (currentAccessPoint.has_value()) {
        object.insert(QStringLiteral("currentAccessPoint"), QJsonValue((*currentAccessPoint).toJson()));
    }
    object.insert(QStringLiteral("state"), QJsonValue(toString(state)));
    return object;
}

} // namespace nymea::api
