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

namespace nymea::api {

ModbusRtuMaster ModbusRtuMaster::fromJson(const QJsonObject &object) {
    ModbusRtuMaster value;
    if (object.contains(QStringLiteral("baudrate"))) {
        value.baudrate = jsonValueToUnsignedInteger(object.value(QStringLiteral("baudrate")));
    }
    if (object.contains(QStringLiteral("connected"))) {
        value.connected = (object.value(QStringLiteral("connected"))).toBool();
    }
    if (object.contains(QStringLiteral("dataBits"))) {
        value.dataBits = parseSerialPortDataBits(object.value(QStringLiteral("dataBits")));
    }
    if (object.contains(QStringLiteral("modbusUuid"))) {
        value.modbusUuid = QUuid((object.value(QStringLiteral("modbusUuid"))).toString());
    }
    if (object.contains(QStringLiteral("numberOfRetries"))) {
        value.numberOfRetries = jsonValueToUnsignedInteger(object.value(QStringLiteral("numberOfRetries")));
    }
    if (object.contains(QStringLiteral("parity"))) {
        value.parity = parseSerialPortParity(object.value(QStringLiteral("parity")));
    }
    if (object.contains(QStringLiteral("serialPort"))) {
        value.serialPort = (object.value(QStringLiteral("serialPort"))).toString();
    }
    if (object.contains(QStringLiteral("stopBits"))) {
        value.stopBits = parseSerialPortStopBits(object.value(QStringLiteral("stopBits")));
    }
    if (object.contains(QStringLiteral("timeout"))) {
        value.timeout = jsonValueToUnsignedInteger(object.value(QStringLiteral("timeout")));
    }
    return value;
}

QJsonObject ModbusRtuMaster::toJson() const {
    QJsonObject object;
    object.insert(QStringLiteral("baudrate"), QJsonValue(static_cast<qint64>(baudrate)));
    object.insert(QStringLiteral("connected"), QJsonValue(connected));
    object.insert(QStringLiteral("dataBits"), QJsonValue(toString(dataBits)));
    object.insert(QStringLiteral("modbusUuid"), QJsonValue((modbusUuid).toString()));
    object.insert(QStringLiteral("numberOfRetries"), QJsonValue(static_cast<qint64>(numberOfRetries)));
    object.insert(QStringLiteral("parity"), QJsonValue(toString(parity)));
    object.insert(QStringLiteral("serialPort"), QJsonValue(serialPort));
    object.insert(QStringLiteral("stopBits"), QJsonValue(toString(stopBits)));
    object.insert(QStringLiteral("timeout"), QJsonValue(static_cast<qint64>(timeout)));
    return object;
}

} // namespace nymea::api
