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

namespace nymea::api {

ScriptsAddScriptResponse ScriptsAddScriptResponse::fromJson(const QJsonObject &object) {
    ScriptsAddScriptResponse value;
    if (object.contains(QStringLiteral("errors"))) {
        value.errors = ([&]() { QStringList list; for (const QJsonValue &item : (object.value(QStringLiteral("errors"))).toArray()) { list.append(item.toString()); } return list; }());
    }
    if (object.contains(QStringLiteral("script"))) {
        value.script = Script::fromJson((object.value(QStringLiteral("script"))).toObject());
    }
    if (object.contains(QStringLiteral("scriptError"))) {
        value.scriptError = parseScriptError(object.value(QStringLiteral("scriptError")));
    }
    return value;
}

QJsonObject ScriptsAddScriptResponse::toJson() const {
    QJsonObject object;
    if (errors.has_value()) {
        object.insert(QStringLiteral("errors"), ([&]() { QJsonArray array; for (const QString &item : *errors) { array.append(item); } return QJsonValue(array); }()));
    }
    if (script.has_value()) {
        object.insert(QStringLiteral("script"), QJsonValue((*script).toJson()));
    }
    object.insert(QStringLiteral("scriptError"), QJsonValue(toString(scriptError)));
    return object;
}

} // namespace nymea::api
