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

namespace nymea::api {

WiredNetworkDevice WiredNetworkDevice::fromJson(const QJsonObject &object) {
    WiredNetworkDevice value;
    if (object.contains(QStringLiteral("bitRate"))) {
        value.bitRate = (object.value(QStringLiteral("bitRate"))).toString();
    }
    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("pluggedIn"))) {
        value.pluggedIn = (object.value(QStringLiteral("pluggedIn"))).toBool();
    }
    if (object.contains(QStringLiteral("state"))) {
        value.state = parseNetworkDeviceState(object.value(QStringLiteral("state")));
    }
    return value;
}

QJsonObject WiredNetworkDevice::toJson() const {
    QJsonObject object;
    object.insert(QStringLiteral("bitRate"), QJsonValue(bitRate));
    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("pluggedIn"), QJsonValue(pluggedIn));
    object.insert(QStringLiteral("state"), QJsonValue(toString(state)));
    return object;
}

} // namespace nymea::api
