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

namespace nymea::api {

UsersSetUserScopesParams UsersSetUserScopesParams::fromJson(const QJsonObject &object) {
    UsersSetUserScopesParams value;
    if (object.contains(QStringLiteral("allowedThingIds"))) {
        value.allowedThingIds = ([&]() { QList<QUuid> list; for (const QJsonValue &item : (object.value(QStringLiteral("allowedThingIds"))).toArray()) { list.append(QUuid((item).toString())); } return list; }());
    }
    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("username"))) {
        value.username = (object.value(QStringLiteral("username"))).toString();
    }
    return value;
}

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

} // namespace nymea::api
