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

namespace nymea::api {

LoggingGetLogEntriesParams LoggingGetLogEntriesParams::fromJson(const QJsonObject &object) {
    LoggingGetLogEntriesParams value;
    if (object.contains(QStringLiteral("columns"))) {
        value.columns = ([&]() { QList<QString> list; for (const QJsonValue &item : (object.value(QStringLiteral("columns"))).toArray()) { list.append((item).toString()); } return list; }());
    }
    if (object.contains(QStringLiteral("endTime"))) {
        value.endTime = jsonValueToUnsignedInteger(object.value(QStringLiteral("endTime")));
    }
    if (object.contains(QStringLiteral("filter"))) {
        value.filter = object.value(QStringLiteral("filter"));
    }
    if (object.contains(QStringLiteral("limit"))) {
        value.limit = jsonValueToInteger(object.value(QStringLiteral("limit")));
    }
    if (object.contains(QStringLiteral("offset"))) {
        value.offset = jsonValueToInteger(object.value(QStringLiteral("offset")));
    }
    if (object.contains(QStringLiteral("sampleRate"))) {
        value.sampleRate = parseSampleRate(object.value(QStringLiteral("sampleRate")));
    }
    if (object.contains(QStringLiteral("sortOrder"))) {
        value.sortOrder = parseSortOrder(object.value(QStringLiteral("sortOrder")));
    }
    if (object.contains(QStringLiteral("startTime"))) {
        value.startTime = jsonValueToUnsignedInteger(object.value(QStringLiteral("startTime")));
    }
    if (object.contains(QStringLiteral("sources"))) {
        value.sources = ([&]() { QList<QString> list; for (const QJsonValue &item : (object.value(QStringLiteral("sources"))).toArray()) { list.append((item).toString()); } return list; }());
    }
    return value;
}

QJsonObject LoggingGetLogEntriesParams::toJson() const {
    QJsonObject object;
    if (columns.has_value()) {
        object.insert(QStringLiteral("columns"), ([&]() { QJsonArray array; for (const auto &item : *columns) { array.append(QJsonValue(item)); } return QJsonValue(array); }()));
    }
    if (endTime.has_value()) {
        object.insert(QStringLiteral("endTime"), QJsonValue(static_cast<qint64>(*endTime)));
    }
    if (filter.has_value()) {
        object.insert(QStringLiteral("filter"), *filter);
    }
    if (limit.has_value()) {
        object.insert(QStringLiteral("limit"), QJsonValue(static_cast<qint64>(*limit)));
    }
    if (offset.has_value()) {
        object.insert(QStringLiteral("offset"), QJsonValue(static_cast<qint64>(*offset)));
    }
    if (sampleRate.has_value()) {
        object.insert(QStringLiteral("sampleRate"), QJsonValue(toString(*sampleRate)));
    }
    if (sortOrder.has_value()) {
        object.insert(QStringLiteral("sortOrder"), QJsonValue(toString(*sortOrder)));
    }
    if (startTime.has_value()) {
        object.insert(QStringLiteral("startTime"), QJsonValue(static_cast<qint64>(*startTime)));
    }
    object.insert(QStringLiteral("sources"), ([&]() { QJsonArray array; for (const auto &item : sources) { array.append(QJsonValue(item)); } return QJsonValue(array); }()));
    return object;
}

} // namespace nymea::api
