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

namespace nymea::api {

IntegrationsPairThingParams IntegrationsPairThingParams::fromJson(const QJsonObject &object) {
    IntegrationsPairThingParams value;
    if (object.contains(QStringLiteral("name"))) {
        value.name = (object.value(QStringLiteral("name"))).toString();
    }
    if (object.contains(QStringLiteral("thingClassId"))) {
        value.thingClassId = QUuid((object.value(QStringLiteral("thingClassId"))).toString());
    }
    if (object.contains(QStringLiteral("thingDescriptorId"))) {
        value.thingDescriptorId = QUuid((object.value(QStringLiteral("thingDescriptorId"))).toString());
    }
    if (object.contains(QStringLiteral("thingId"))) {
        value.thingId = QUuid((object.value(QStringLiteral("thingId"))).toString());
    }
    if (object.contains(QStringLiteral("thingParams"))) {
        value.thingParams = ([&]() { QList<Param> list; for (const QJsonValue &item : (object.value(QStringLiteral("thingParams"))).toArray()) { list.append(Param::fromJson((item).toObject())); } return list; }());
    }
    return value;
}

QJsonObject IntegrationsPairThingParams::toJson() const {
    QJsonObject object;
    if (name.has_value()) {
        object.insert(QStringLiteral("name"), QJsonValue(*name));
    }
    if (thingClassId.has_value()) {
        object.insert(QStringLiteral("thingClassId"), QJsonValue((*thingClassId).toString()));
    }
    if (thingDescriptorId.has_value()) {
        object.insert(QStringLiteral("thingDescriptorId"), QJsonValue((*thingDescriptorId).toString()));
    }
    if (thingId.has_value()) {
        object.insert(QStringLiteral("thingId"), QJsonValue((*thingId).toString()));
    }
    if (thingParams.has_value()) {
        object.insert(QStringLiteral("thingParams"), ([&]() { QJsonArray array; for (const auto &item : *thingParams) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    }
    return object;
}

} // namespace nymea::api
