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

namespace nymea::api {

MqttPolicy MqttPolicy::fromJson(const QJsonObject &object) {
    MqttPolicy value;
    if (object.contains(QStringLiteral("allowedPublishTopicFilters"))) {
        value.allowedPublishTopicFilters = ([&]() { QStringList list; for (const QJsonValue &item : (object.value(QStringLiteral("allowedPublishTopicFilters"))).toArray()) { list.append(item.toString()); } return list; }());
    }
    if (object.contains(QStringLiteral("allowedSubscribeTopicFilters"))) {
        value.allowedSubscribeTopicFilters = ([&]() { QStringList list; for (const QJsonValue &item : (object.value(QStringLiteral("allowedSubscribeTopicFilters"))).toArray()) { list.append(item.toString()); } return list; }());
    }
    if (object.contains(QStringLiteral("clientId"))) {
        value.clientId = (object.value(QStringLiteral("clientId"))).toString();
    }
    if (object.contains(QStringLiteral("password"))) {
        value.password = (object.value(QStringLiteral("password"))).toString();
    }
    if (object.contains(QStringLiteral("username"))) {
        value.username = (object.value(QStringLiteral("username"))).toString();
    }
    return value;
}

QJsonObject MqttPolicy::toJson() const {
    QJsonObject object;
    object.insert(QStringLiteral("allowedPublishTopicFilters"), ([&]() { QJsonArray array; for (const QString &item : allowedPublishTopicFilters) { array.append(item); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("allowedSubscribeTopicFilters"), ([&]() { QJsonArray array; for (const QString &item : allowedSubscribeTopicFilters) { array.append(item); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("clientId"), QJsonValue(clientId));
    object.insert(QStringLiteral("password"), QJsonValue(password));
    object.insert(QStringLiteral("username"), QJsonValue(username));
    return object;
}

} // namespace nymea::api
