#ifndef TACTILEIPC3D_SERIAL_TRANSPORT_H
#define TACTILEIPC3D_SERIAL_TRANSPORT_H

#include <QObject>
#include <QByteArray>

#include "serial_types.h"

class ISerialTransport : public QObject {
    Q_OBJECT
public:
    explicit ISerialTransport(QObject* parent = nullptr) : QObject(parent) {}
    ~ISerialTransport() override = default;

    virtual bool open(const SerialConfig& config, QString* error) = 0;
    virtual void close() = 0;
    virtual bool writeBytes(const QByteArray& data, QString* error) = 0;

signals:
    void bytesReceived(const QByteArray& data);
};

class NullSerialTransport : public ISerialTransport {
    Q_OBJECT
public:
    explicit NullSerialTransport(QObject* parent = nullptr) : ISerialTransport(parent) {}

    bool open(const SerialConfig& config, QString* error) override {
        Q_UNUSED(config)
        if (error)
            error->clear();
        return true;
    }

    void close() override {}

    bool writeBytes(const QByteArray& data, QString* error) override {
        Q_UNUSED(data)
        if (error)
            error->clear();
        return true;
    }
};

#endif // TACTILEIPC3D_SERIAL_TRANSPORT_H
