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

namespace nymea::api {

ThingClass ThingClass::fromJson(const QJsonObject &object) {
    ThingClass value;
    if (object.contains(QStringLiteral("actionTypes"))) {
        value.actionTypes = ([&]() { QList<ActionType> list; for (const QJsonValue &item : (object.value(QStringLiteral("actionTypes"))).toArray()) { list.append(ActionType::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("browsable"))) {
        value.browsable = (object.value(QStringLiteral("browsable"))).toBool();
    }
    if (object.contains(QStringLiteral("browserItemActionTypes"))) {
        value.browserItemActionTypes = ([&]() { QList<ActionType> list; for (const QJsonValue &item : (object.value(QStringLiteral("browserItemActionTypes"))).toArray()) { list.append(ActionType::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("createMethods"))) {
        value.createMethods = ([&]() { QList<CreateMethod> list; for (const QJsonValue &item : (object.value(QStringLiteral("createMethods"))).toArray()) { list.append(parseCreateMethod(item)); } return list; }());
    }
    if (object.contains(QStringLiteral("discoveryParamTypes"))) {
        value.discoveryParamTypes = ([&]() { QList<ParamType> list; for (const QJsonValue &item : (object.value(QStringLiteral("discoveryParamTypes"))).toArray()) { list.append(ParamType::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("discoveryType"))) {
        value.discoveryType = parseDiscoveryType(object.value(QStringLiteral("discoveryType")));
    }
    if (object.contains(QStringLiteral("displayName"))) {
        value.displayName = (object.value(QStringLiteral("displayName"))).toString();
    }
    if (object.contains(QStringLiteral("eventTypes"))) {
        value.eventTypes = ([&]() { QList<EventType> list; for (const QJsonValue &item : (object.value(QStringLiteral("eventTypes"))).toArray()) { list.append(EventType::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("id"))) {
        value.id = QUuid((object.value(QStringLiteral("id"))).toString());
    }
    if (object.contains(QStringLiteral("interfaces"))) {
        value.interfaces = ([&]() { QStringList list; for (const QJsonValue &item : (object.value(QStringLiteral("interfaces"))).toArray()) { list.append(item.toString()); } return list; }());
    }
    if (object.contains(QStringLiteral("name"))) {
        value.name = (object.value(QStringLiteral("name"))).toString();
    }
    if (object.contains(QStringLiteral("paramTypes"))) {
        value.paramTypes = ([&]() { QList<ParamType> list; for (const QJsonValue &item : (object.value(QStringLiteral("paramTypes"))).toArray()) { list.append(ParamType::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("pluginId"))) {
        value.pluginId = QUuid((object.value(QStringLiteral("pluginId"))).toString());
    }
    if (object.contains(QStringLiteral("providedInterfaces"))) {
        value.providedInterfaces = ([&]() { QStringList list; for (const QJsonValue &item : (object.value(QStringLiteral("providedInterfaces"))).toArray()) { list.append(item.toString()); } return list; }());
    }
    if (object.contains(QStringLiteral("settingsTypes"))) {
        value.settingsTypes = ([&]() { QList<ParamType> list; for (const QJsonValue &item : (object.value(QStringLiteral("settingsTypes"))).toArray()) { list.append(ParamType::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("setupMethod"))) {
        value.setupMethod = parseSetupMethod(object.value(QStringLiteral("setupMethod")));
    }
    if (object.contains(QStringLiteral("stateTypes"))) {
        value.stateTypes = ([&]() { QList<StateType> list; for (const QJsonValue &item : (object.value(QStringLiteral("stateTypes"))).toArray()) { list.append(StateType::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("vendorId"))) {
        value.vendorId = QUuid((object.value(QStringLiteral("vendorId"))).toString());
    }
    return value;
}

QJsonObject ThingClass::toJson() const {
    QJsonObject object;
    object.insert(QStringLiteral("actionTypes"), ([&]() { QJsonArray array; for (const auto &item : actionTypes) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("browsable"), QJsonValue(browsable));
    object.insert(QStringLiteral("browserItemActionTypes"), ([&]() { QJsonArray array; for (const auto &item : browserItemActionTypes) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("createMethods"), ([&]() { QJsonArray array; for (const auto &item : createMethods) { array.append(QJsonValue(toString(item))); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("discoveryParamTypes"), ([&]() { QJsonArray array; for (const auto &item : discoveryParamTypes) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("discoveryType"), QJsonValue(toString(discoveryType)));
    object.insert(QStringLiteral("displayName"), QJsonValue(displayName));
    object.insert(QStringLiteral("eventTypes"), ([&]() { QJsonArray array; for (const auto &item : eventTypes) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("id"), QJsonValue((id).toString()));
    object.insert(QStringLiteral("interfaces"), ([&]() { QJsonArray array; for (const QString &item : interfaces) { array.append(item); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("name"), QJsonValue(name));
    object.insert(QStringLiteral("paramTypes"), ([&]() { QJsonArray array; for (const auto &item : paramTypes) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("pluginId"), QJsonValue((pluginId).toString()));
    object.insert(QStringLiteral("providedInterfaces"), ([&]() { QJsonArray array; for (const QString &item : providedInterfaces) { array.append(item); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("settingsTypes"), ([&]() { QJsonArray array; for (const auto &item : settingsTypes) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("setupMethod"), QJsonValue(toString(setupMethod)));
    object.insert(QStringLiteral("stateTypes"), ([&]() { QJsonArray array; for (const auto &item : stateTypes) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("vendorId"), QJsonValue((vendorId).toString()));
    return object;
}

} // namespace nymea::api
