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

namespace nymea::api {

BrowserItem BrowserItem::fromJson(const QJsonObject &object) {
    BrowserItem value;
    if (object.contains(QStringLiteral("actionTypeIds"))) {
        value.actionTypeIds = ([&]() { QList<QUuid> list; for (const QJsonValue &item : (object.value(QStringLiteral("actionTypeIds"))).toArray()) { list.append(QUuid((item).toString())); } return list; }());
    }
    if (object.contains(QStringLiteral("browsable"))) {
        value.browsable = (object.value(QStringLiteral("browsable"))).toBool();
    }
    if (object.contains(QStringLiteral("description"))) {
        value.description = (object.value(QStringLiteral("description"))).toString();
    }
    if (object.contains(QStringLiteral("disabled"))) {
        value.disabled = (object.value(QStringLiteral("disabled"))).toBool();
    }
    if (object.contains(QStringLiteral("displayName"))) {
        value.displayName = (object.value(QStringLiteral("displayName"))).toString();
    }
    if (object.contains(QStringLiteral("executable"))) {
        value.executable = (object.value(QStringLiteral("executable"))).toBool();
    }
    if (object.contains(QStringLiteral("icon"))) {
        value.icon = parseBrowserIcon(object.value(QStringLiteral("icon")));
    }
    if (object.contains(QStringLiteral("id"))) {
        value.id = (object.value(QStringLiteral("id"))).toString();
    }
    if (object.contains(QStringLiteral("mediaIcon"))) {
        value.mediaIcon = parseMediaBrowserIcon(object.value(QStringLiteral("mediaIcon")));
    }
    if (object.contains(QStringLiteral("thumbnail"))) {
        value.thumbnail = (object.value(QStringLiteral("thumbnail"))).toString();
    }
    return value;
}

QJsonObject BrowserItem::toJson() const {
    QJsonObject object;
    object.insert(QStringLiteral("actionTypeIds"), ([&]() { QJsonArray array; for (const auto &item : actionTypeIds) { array.append(QJsonValue((item).toString())); } return QJsonValue(array); }()));
    object.insert(QStringLiteral("browsable"), QJsonValue(browsable));
    object.insert(QStringLiteral("description"), QJsonValue(description));
    object.insert(QStringLiteral("disabled"), QJsonValue(disabled));
    object.insert(QStringLiteral("displayName"), QJsonValue(displayName));
    object.insert(QStringLiteral("executable"), QJsonValue(executable));
    object.insert(QStringLiteral("icon"), QJsonValue(toString(icon)));
    object.insert(QStringLiteral("id"), QJsonValue(id));
    if (mediaIcon.has_value()) {
        object.insert(QStringLiteral("mediaIcon"), QJsonValue(toString(*mediaIcon)));
    }
    object.insert(QStringLiteral("thumbnail"), QJsonValue(thumbnail));
    return object;
}

} // namespace nymea::api
