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

namespace nymea::api {

JSONRPCAuthenticateResponse JSONRPCAuthenticateResponse::fromJson(const QJsonObject &object) {
    JSONRPCAuthenticateResponse value;
    if (object.contains(QStringLiteral("scopes"))) {
        value.scopes = ([&]() { QList<PermissionScope> list; for (const QJsonValue &item : (object.value(QStringLiteral("scopes"))).toArray()) { list.append(parsePermissionScope(item)); } return list; }());
    }
    if (object.contains(QStringLiteral("token"))) {
        value.token = (object.value(QStringLiteral("token"))).toString();
    }
    if (object.contains(QStringLiteral("username"))) {
        value.username = (object.value(QStringLiteral("username"))).toString();
    }
    if (object.contains(QStringLiteral("success"))) {
        value.success = (object.value(QStringLiteral("success"))).toBool();
    }
    return value;
}

QJsonObject JSONRPCAuthenticateResponse::toJson() const {
    QJsonObject object;
    if (scopes.has_value()) {
        object.insert(QStringLiteral("scopes"), ([&]() { QJsonArray array; for (const auto &item : *scopes) { array.append(QJsonValue(toString(item))); } return QJsonValue(array); }()));
    }
    if (token.has_value()) {
        object.insert(QStringLiteral("token"), QJsonValue(*token));
    }
    if (username.has_value()) {
        object.insert(QStringLiteral("username"), QJsonValue(*username));
    }
    object.insert(QStringLiteral("success"), QJsonValue(success));
    return object;
}

} // namespace nymea::api
