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

namespace nymea::api {

TimeDescriptor TimeDescriptor::fromJson(const QJsonObject &object) {
    TimeDescriptor value;
    if (object.contains(QStringLiteral("calendarItems"))) {
        value.calendarItems = ([&]() { QList<CalendarItem> list; for (const QJsonValue &item : (object.value(QStringLiteral("calendarItems"))).toArray()) { list.append(CalendarItem::fromJson((item).toObject())); } return list; }());
    }
    if (object.contains(QStringLiteral("timeEventItems"))) {
        value.timeEventItems = ([&]() { QList<TimeEventItem> list; for (const QJsonValue &item : (object.value(QStringLiteral("timeEventItems"))).toArray()) { list.append(TimeEventItem::fromJson((item).toObject())); } return list; }());
    }
    return value;
}

QJsonObject TimeDescriptor::toJson() const {
    QJsonObject object;
    if (calendarItems.has_value()) {
        object.insert(QStringLiteral("calendarItems"), ([&]() { QJsonArray array; for (const auto &item : *calendarItems) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    }
    if (timeEventItems.has_value()) {
        object.insert(QStringLiteral("timeEventItems"), ([&]() { QJsonArray array; for (const auto &item : *timeEventItems) { array.append(QJsonValue((item).toJson())); } return QJsonValue(array); }()));
    }
    return object;
}

} // namespace nymea::api
