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

namespace nymea::api {

IntegrationsBrowseThingResponse IntegrationsBrowseThingResponse::fromJson(const QJsonObject &object) {
    IntegrationsBrowseThingResponse value;
    if (object.contains(QStringLiteral("displayMessage"))) {
        value.displayMessage = (object.value(QStringLiteral("displayMessage"))).toString();
    }
    if (object.contains(QStringLiteral("items"))) {
        value.items = ([&]() { QList<BrowserItem> list; for (const QJsonValue &item : (object.value(QStringLiteral("items"))).toArray()) { list.append(BrowserItem::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("thingError"))) {
        value.thingError = parseThingError(object.value(QStringLiteral("thingError")));
    }
    return value;
}

QJsonObject IntegrationsBrowseThingResponse::toJson() const {
    QJsonObject object;
    if (displayMessage.has_value()) {
        object.insert(QStringLiteral("displayMessage"), QJsonValue(*displayMessage));
    }
    if (items.has_value()) {
        object.insert(QStringLiteral("items"), ([&]() { QJsonArray array; for (const auto &item : *items) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    }
    object.insert(QStringLiteral("thingError"), QJsonValue(toString(thingError)));
    return object;
}

} // namespace nymea::api
