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

namespace nymea::api {

StateEvaluator StateEvaluator::fromJson(const QJsonObject &object) {
    StateEvaluator value;
    if (object.contains(QStringLiteral("childEvaluators"))) {
        value.childEvaluators = ([&]() { QList<QSharedPointer<StateEvaluator>> list; for (const QJsonValue &item : (object.value(QStringLiteral("childEvaluators"))).toArray()) { list.append(QSharedPointer<StateEvaluator>::create(StateEvaluator::fromJson((item).toObject()))); } return list; }());
    }
    if (object.contains(QStringLiteral("operator"))) {
        value.operatorValue = parseStateOperator(object.value(QStringLiteral("operator")));
    }
    if (object.contains(QStringLiteral("stateDescriptor"))) {
        value.stateDescriptor = StateDescriptor::fromJson((object.value(QStringLiteral("stateDescriptor"))).toObject());
    }
    return value;
}

QJsonObject StateEvaluator::toJson() const {
    QJsonObject object;
    if (childEvaluators.has_value()) {
        object.insert(QStringLiteral("childEvaluators"), ([&]() { QJsonArray array; for (const auto &item : *childEvaluators) { array.append(((item) ? QJsonValue((item)->toJson()) : QJsonValue(QJsonObject{}))); } return QJsonValue(array); }()));
    }
    if (operatorValue.has_value()) {
        object.insert(QStringLiteral("operator"), QJsonValue(toString(*operatorValue)));
    }
    if (stateDescriptor.has_value()) {
        object.insert(QStringLiteral("stateDescriptor"), QJsonValue((*stateDescriptor).toJson()));
    }
    return object;
}

} // namespace nymea::api
