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

namespace nymea::api {

EventDescriptor EventDescriptor::fromJson(const QJsonObject &object) {
    EventDescriptor value;
    if (object.contains(QStringLiteral("eventTypeId"))) {
        value.eventTypeId = QUuid((object.value(QStringLiteral("eventTypeId"))).toString());
    }
    if (object.contains(QStringLiteral("interface"))) {
        value.interface = (object.value(QStringLiteral("interface"))).toString();
    }
    if (object.contains(QStringLiteral("interfaceEvent"))) {
        value.interfaceEvent = (object.value(QStringLiteral("interfaceEvent"))).toString();
    }
    if (object.contains(QStringLiteral("paramDescriptors"))) {
        value.paramDescriptors = ([&]() { QList<ParamDescriptor> list; for (const QJsonValue &item : (object.value(QStringLiteral("paramDescriptors"))).toArray()) { list.append(ParamDescriptor::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("thingId"))) {
        value.thingId = QUuid((object.value(QStringLiteral("thingId"))).toString());
    }
    return value;
}

QJsonObject EventDescriptor::toJson() const {
    QJsonObject object;
    if (eventTypeId.has_value()) {
        object.insert(QStringLiteral("eventTypeId"), QJsonValue((*eventTypeId).toString()));
    }
    if (interface.has_value()) {
        object.insert(QStringLiteral("interface"), QJsonValue(*interface));
    }
    if (interfaceEvent.has_value()) {
        object.insert(QStringLiteral("interfaceEvent"), QJsonValue(*interfaceEvent));
    }
    if (paramDescriptors.has_value()) {
        object.insert(QStringLiteral("paramDescriptors"), ([&]() { QJsonArray array; for (const auto &item : *paramDescriptors) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    }
    if (thingId.has_value()) {
        object.insert(QStringLiteral("thingId"), QJsonValue((*thingId).toString()));
    }
    return object;
}

} // namespace nymea::api
