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

namespace nymea::api {

TimeEventItem TimeEventItem::fromJson(const QJsonObject &object) {
    TimeEventItem value;
    if (object.contains(QStringLiteral("datetime"))) {
        value.datetime = jsonValueToUnsignedInteger(object.value(QStringLiteral("datetime")));
    }
    if (object.contains(QStringLiteral("repeating"))) {
        value.repeating = RepeatingOption::fromJson((object.value(QStringLiteral("repeating"))).toObject());
    }
    if (object.contains(QStringLiteral("time"))) {
        value.time = jsonValueToInteger(object.value(QStringLiteral("time")));
    }
    return value;
}

QJsonObject TimeEventItem::toJson() const {
    QJsonObject object;
    if (datetime.has_value()) {
        object.insert(QStringLiteral("datetime"), QJsonValue(static_cast<qint64>(*datetime)));
    }
    if (repeating.has_value()) {
        object.insert(QStringLiteral("repeating"), QJsonValue((*repeating).toJson()));
    }
    if (time.has_value()) {
        object.insert(QStringLiteral("time"), QJsonValue(static_cast<qint64>(*time)));
    }
    return object;
}

} // namespace nymea::api
