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

namespace nymea::api {

Tag Tag::fromJson(const QJsonObject &object) {
    Tag value;
    if (object.contains(QStringLiteral("appId"))) {
        value.appId = (object.value(QStringLiteral("appId"))).toString();
    }
    if (object.contains(QStringLiteral("ruleId"))) {
        value.ruleId = QUuid((object.value(QStringLiteral("ruleId"))).toString());
    }
    if (object.contains(QStringLiteral("thingId"))) {
        value.thingId = QUuid((object.value(QStringLiteral("thingId"))).toString());
    }
    if (object.contains(QStringLiteral("value"))) {
        value.value = (object.value(QStringLiteral("value"))).toString();
    }
    if (object.contains(QStringLiteral("tagId"))) {
        value.tagId = (object.value(QStringLiteral("tagId"))).toString();
    }
    return value;
}

QJsonObject Tag::toJson() const {
    QJsonObject object;
    object.insert(QStringLiteral("appId"), QJsonValue(appId));
    if (ruleId.has_value()) {
        object.insert(QStringLiteral("ruleId"), QJsonValue((*ruleId).toString()));
    }
    if (thingId.has_value()) {
        object.insert(QStringLiteral("thingId"), QJsonValue((*thingId).toString()));
    }
    if (value.has_value()) {
        object.insert(QStringLiteral("value"), QJsonValue(*value));
    }
    object.insert(QStringLiteral("tagId"), QJsonValue(tagId));
    return object;
}

} // namespace nymea::api
