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

namespace nymea::api {

RepeatingOption RepeatingOption::fromJson(const QJsonObject &object) {
    RepeatingOption value;
    if (object.contains(QStringLiteral("mode"))) {
        value.mode = parseRepeatingMode(object.value(QStringLiteral("mode")));
    }
    if (object.contains(QStringLiteral("monthDays"))) {
        value.monthDays = ([&]() { QList<qint64> list; for (const QJsonValue &item : (object.value(QStringLiteral("monthDays"))).toArray()) { list.append(jsonValueToInteger(item)); } return list; }());
    }
    if (object.contains(QStringLiteral("weekDays"))) {
        value.weekDays = ([&]() { QList<qint64> list; for (const QJsonValue &item : (object.value(QStringLiteral("weekDays"))).toArray()) { list.append(jsonValueToInteger(item)); } return list; }());
    }
    return value;
}

QJsonObject RepeatingOption::toJson() const {
    QJsonObject object;
    object.insert(QStringLiteral("mode"), QJsonValue(toString(mode)));
    if (monthDays.has_value()) {
        object.insert(QStringLiteral("monthDays"), ([&]() { QJsonArray array; for (const auto &item : *monthDays) { array.append(QJsonValue(static_cast<qint64>(item))); } return QJsonValue(array); }()));
    }
    if (weekDays.has_value()) {
        object.insert(QStringLiteral("weekDays"), ([&]() { QJsonArray array; for (const auto &item : *weekDays) { array.append(QJsonValue(static_cast<qint64>(item))); } return QJsonValue(array); }()));
    }
    return object;
}

} // namespace nymea::api
