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

namespace nymea::api {

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

QJsonObject ThingDescriptor::toJson() const {
    QJsonObject object;
    object.insert(QStringLiteral("description"), QJsonValue(description));
    object.insert(QStringLiteral("id"), QJsonValue((id).toString()));
    if (thingId.has_value()) {
        object.insert(QStringLiteral("thingId"), QJsonValue((*thingId).toString()));
    }
    object.insert(QStringLiteral("params"), ([&]() { QJsonArray array; for (const auto &item : params) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("thingClassId"), QJsonValue((thingClassId).toString()));
    object.insert(QStringLiteral("title"), QJsonValue(title));
    return object;
}

} // namespace nymea::api
