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

namespace nymea::api {

StateDescriptor StateDescriptor::fromJson(const QJsonObject &object) {
    StateDescriptor value;
    if (object.contains(QStringLiteral("interface"))) {
        value.interface = (object.value(QStringLiteral("interface"))).toString();
    }
    if (object.contains(QStringLiteral("interfaceState"))) {
        value.interfaceState = (object.value(QStringLiteral("interfaceState"))).toString();
    }
    if (object.contains(QStringLiteral("stateTypeId"))) {
        value.stateTypeId = QUuid((object.value(QStringLiteral("stateTypeId"))).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"));
    }
    if (object.contains(QStringLiteral("valueStateTypeId"))) {
        value.valueStateTypeId = QUuid((object.value(QStringLiteral("valueStateTypeId"))).toString());
    }
    if (object.contains(QStringLiteral("valueThingId"))) {
        value.valueThingId = QUuid((object.value(QStringLiteral("valueThingId"))).toString());
    }
    if (object.contains(QStringLiteral("operator"))) {
        value.operatorValue = parseValueOperator(object.value(QStringLiteral("operator")));
    }
    return value;
}

QJsonObject StateDescriptor::toJson() const {
    QJsonObject object;
    if (interface.has_value()) {
        object.insert(QStringLiteral("interface"), QJsonValue(*interface));
    }
    if (interfaceState.has_value()) {
        object.insert(QStringLiteral("interfaceState"), QJsonValue(*interfaceState));
    }
    if (stateTypeId.has_value()) {
        object.insert(QStringLiteral("stateTypeId"), QJsonValue((*stateTypeId).toString()));
    }
    if (thingId.has_value()) {
        object.insert(QStringLiteral("thingId"), QJsonValue((*thingId).toString()));
    }
    if (value.has_value()) {
        object.insert(QStringLiteral("value"), *value);
    }
    if (valueStateTypeId.has_value()) {
        object.insert(QStringLiteral("valueStateTypeId"), QJsonValue((*valueStateTypeId).toString()));
    }
    if (valueThingId.has_value()) {
        object.insert(QStringLiteral("valueThingId"), QJsonValue((*valueThingId).toString()));
    }
    object.insert(QStringLiteral("operator"), QJsonValue(toString(operatorValue)));
    return object;
}

} // namespace nymea::api
