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

namespace nymea::api {

ParamType ParamType::fromJson(const QJsonObject &object) {
    ParamType value;
    if (object.contains(QStringLiteral("displayName"))) {
        value.displayName = (object.value(QStringLiteral("displayName"))).toString();
    }
    if (object.contains(QStringLiteral("index"))) {
        value.index = jsonValueToInteger(object.value(QStringLiteral("index")));
    }
    if (object.contains(QStringLiteral("name"))) {
        value.name = (object.value(QStringLiteral("name"))).toString();
    }
    if (object.contains(QStringLiteral("allowedValues"))) {
        value.allowedValues = ([&]() { QList<QJsonValue> list; for (const QJsonValue &item : (object.value(QStringLiteral("allowedValues"))).toArray()) { list.append(item); } return list; }());
    }
    if (object.contains(QStringLiteral("defaultValue"))) {
        value.defaultValue = object.value(QStringLiteral("defaultValue"));
    }
    if (object.contains(QStringLiteral("inputType"))) {
        value.inputType = parseInputType(object.value(QStringLiteral("inputType")));
    }
    if (object.contains(QStringLiteral("maxValue"))) {
        value.maxValue = object.value(QStringLiteral("maxValue"));
    }
    if (object.contains(QStringLiteral("minValue"))) {
        value.minValue = object.value(QStringLiteral("minValue"));
    }
    if (object.contains(QStringLiteral("readOnly"))) {
        value.readOnly = (object.value(QStringLiteral("readOnly"))).toBool();
    }
    if (object.contains(QStringLiteral("stepSize"))) {
        value.stepSize = (object.value(QStringLiteral("stepSize"))).toDouble();
    }
    if (object.contains(QStringLiteral("unit"))) {
        value.unit = parseUnit(object.value(QStringLiteral("unit")));
    }
    if (object.contains(QStringLiteral("id"))) {
        value.id = QUuid((object.value(QStringLiteral("id"))).toString());
    }
    if (object.contains(QStringLiteral("type"))) {
        value.type = parseBasicType(object.value(QStringLiteral("type")));
    }
    return value;
}

QJsonObject ParamType::toJson() const {
    QJsonObject object;
    object.insert(QStringLiteral("displayName"), QJsonValue(displayName));
    object.insert(QStringLiteral("index"), QJsonValue(static_cast<qint64>(index)));
    object.insert(QStringLiteral("name"), QJsonValue(name));
    if (allowedValues.has_value()) {
        object.insert(QStringLiteral("allowedValues"), ([&]() { QJsonArray array; for (const auto &item : *allowedValues) { array.append(item); } return QJsonValue(array); }()));
    }
    if (defaultValue.has_value()) {
        object.insert(QStringLiteral("defaultValue"), *defaultValue);
    }
    if (inputType.has_value()) {
        object.insert(QStringLiteral("inputType"), QJsonValue(toString(*inputType)));
    }
    if (maxValue.has_value()) {
        object.insert(QStringLiteral("maxValue"), *maxValue);
    }
    if (minValue.has_value()) {
        object.insert(QStringLiteral("minValue"), *minValue);
    }
    if (readOnly.has_value()) {
        object.insert(QStringLiteral("readOnly"), QJsonValue(*readOnly));
    }
    if (stepSize.has_value()) {
        object.insert(QStringLiteral("stepSize"), QJsonValue(*stepSize));
    }
    if (unit.has_value()) {
        object.insert(QStringLiteral("unit"), QJsonValue(toString(*unit)));
    }
    object.insert(QStringLiteral("id"), QJsonValue((id).toString()));
    object.insert(QStringLiteral("type"), QJsonValue(toString(type)));
    return object;
}

} // namespace nymea::api
