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

namespace nymea::api {

RuleAction RuleAction::fromJson(const QJsonObject &object) {
    RuleAction value;
    if (object.contains(QStringLiteral("actionTypeId"))) {
        value.actionTypeId = QUuid((object.value(QStringLiteral("actionTypeId"))).toString());
    }
    if (object.contains(QStringLiteral("browserItemId"))) {
        value.browserItemId = (object.value(QStringLiteral("browserItemId"))).toString();
    }
    if (object.contains(QStringLiteral("interface"))) {
        value.interface = (object.value(QStringLiteral("interface"))).toString();
    }
    if (object.contains(QStringLiteral("interfaceAction"))) {
        value.interfaceAction = (object.value(QStringLiteral("interfaceAction"))).toString();
    }
    if (object.contains(QStringLiteral("ruleActionParams"))) {
        value.ruleActionParams = ([&]() { QList<RuleActionParam> list; for (const QJsonValue &item : (object.value(QStringLiteral("ruleActionParams"))).toArray()) { list.append(RuleActionParam::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("thingId"))) {
        value.thingId = QUuid((object.value(QStringLiteral("thingId"))).toString());
    }
    return value;
}

QJsonObject RuleAction::toJson() const {
    QJsonObject object;
    if (actionTypeId.has_value()) {
        object.insert(QStringLiteral("actionTypeId"), QJsonValue((*actionTypeId).toString()));
    }
    if (browserItemId.has_value()) {
        object.insert(QStringLiteral("browserItemId"), QJsonValue(*browserItemId));
    }
    if (interface.has_value()) {
        object.insert(QStringLiteral("interface"), QJsonValue(*interface));
    }
    if (interfaceAction.has_value()) {
        object.insert(QStringLiteral("interfaceAction"), QJsonValue(*interfaceAction));
    }
    if (ruleActionParams.has_value()) {
        object.insert(QStringLiteral("ruleActionParams"), ([&]() { QJsonArray array; for (const auto &item : *ruleActionParams) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    }
    if (thingId.has_value()) {
        object.insert(QStringLiteral("thingId"), QJsonValue((*thingId).toString()));
    }
    return object;
}

} // namespace nymea::api
