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

namespace nymea::api {

ModbusRtuGetModbusRtuMastersResponse ModbusRtuGetModbusRtuMastersResponse::fromJson(const QJsonObject &object) {
    ModbusRtuGetModbusRtuMastersResponse value;
    if (object.contains(QStringLiteral("modbusError"))) {
        value.modbusError = parseModbusRtuError(object.value(QStringLiteral("modbusError")));
    }
    if (object.contains(QStringLiteral("modbusRtuMasters"))) {
        value.modbusRtuMasters = ([&]() { QList<ModbusRtuMaster> list; for (const QJsonValue &item : (object.value(QStringLiteral("modbusRtuMasters"))).toArray()) { list.append(ModbusRtuMaster::fromJson((item).toObject())); } return list; }());
    }
    return value;
}

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

} // namespace nymea::api
