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

namespace nymea::api {

JSONRPCHelloResponse JSONRPCHelloResponse::fromJson(const QJsonObject &object) {
    JSONRPCHelloResponse value;
    if (object.contains(QStringLiteral("authenticationRequired"))) {
        value.authenticationRequired = (object.value(QStringLiteral("authenticationRequired"))).toBool();
    }
    if (object.contains(QStringLiteral("initialSetupRequired"))) {
        value.initialSetupRequired = (object.value(QStringLiteral("initialSetupRequired"))).toBool();
    }
    if (object.contains(QStringLiteral("language"))) {
        value.language = (object.value(QStringLiteral("language"))).toString();
    }
    if (object.contains(QStringLiteral("locale"))) {
        value.locale = (object.value(QStringLiteral("locale"))).toString();
    }
    if (object.contains(QStringLiteral("name"))) {
        value.name = (object.value(QStringLiteral("name"))).toString();
    }
    if (object.contains(QStringLiteral("authenticated"))) {
        value.authenticated = (object.value(QStringLiteral("authenticated"))).toBool();
    }
    if (object.contains(QStringLiteral("cacheHashes"))) {
        value.cacheHashes = ([&]() { QList<CacheHash> list; for (const QJsonValue &item : (object.value(QStringLiteral("cacheHashes"))).toArray()) { list.append(CacheHash::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("experiences"))) {
        value.experiences = ([&]() { QList<Experience> list; for (const QJsonValue &item : (object.value(QStringLiteral("experiences"))).toArray()) { list.append(Experience::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("permissionScopes"))) {
        value.permissionScopes = ([&]() { QList<PermissionScope> list; for (const QJsonValue &item : (object.value(QStringLiteral("permissionScopes"))).toArray()) { list.append(parsePermissionScope(item)); } return list; }());
    }
    if (object.contains(QStringLiteral("username"))) {
        value.username = (object.value(QStringLiteral("username"))).toString();
    }
    if (object.contains(QStringLiteral("protocol version"))) {
        value.protocolVersion = (object.value(QStringLiteral("protocol version"))).toString();
    }
    if (object.contains(QStringLiteral("pushButtonAuthAvailable"))) {
        value.pushButtonAuthAvailable = (object.value(QStringLiteral("pushButtonAuthAvailable"))).toBool();
    }
    if (object.contains(QStringLiteral("server"))) {
        value.server = (object.value(QStringLiteral("server"))).toString();
    }
    if (object.contains(QStringLiteral("uuid"))) {
        value.uuid = QUuid((object.value(QStringLiteral("uuid"))).toString());
    }
    if (object.contains(QStringLiteral("version"))) {
        value.version = (object.value(QStringLiteral("version"))).toString();
    }
    return value;
}

QJsonObject JSONRPCHelloResponse::toJson() const {
    QJsonObject object;
    object.insert(QStringLiteral("authenticationRequired"), QJsonValue(authenticationRequired));
    object.insert(QStringLiteral("initialSetupRequired"), QJsonValue(initialSetupRequired));
    object.insert(QStringLiteral("language"), QJsonValue(language));
    object.insert(QStringLiteral("locale"), QJsonValue(locale));
    object.insert(QStringLiteral("name"), QJsonValue(name));
    if (authenticated.has_value()) {
        object.insert(QStringLiteral("authenticated"), QJsonValue(*authenticated));
    }
    if (cacheHashes.has_value()) {
        object.insert(QStringLiteral("cacheHashes"), ([&]() { QJsonArray array; for (const auto &item : *cacheHashes) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    }
    if (experiences.has_value()) {
        object.insert(QStringLiteral("experiences"), ([&]() { QJsonArray array; for (const auto &item : *experiences) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    }
    if (permissionScopes.has_value()) {
        object.insert(QStringLiteral("permissionScopes"), ([&]() { QJsonArray array; for (const auto &item : *permissionScopes) { array.append(QJsonValue(toString(item))); } return QJsonValue(array); }()));
    }
    if (username.has_value()) {
        object.insert(QStringLiteral("username"), QJsonValue(*username));
    }
    object.insert(QStringLiteral("protocol version"), QJsonValue(protocolVersion));
    object.insert(QStringLiteral("pushButtonAuthAvailable"), QJsonValue(pushButtonAuthAvailable));
    object.insert(QStringLiteral("server"), QJsonValue(server));
    object.insert(QStringLiteral("uuid"), QJsonValue((uuid).toString()));
    object.insert(QStringLiteral("version"), QJsonValue(version));
    return object;
}

} // namespace nymea::api
