#ifndef DEVICEBASE_H
#define DEVICEBASE_H

#include <QObject>
#include "common/utils/QSerialPortUtil.h"
#include "common/utils/QKafkaProducer.h"
#include "common/utils/QByteUtil.h"
#include "common/utils/QLogUtil.h"
#include "common/utils/SettingConfig.h"

#include "protocol/dto/DeviceFrameBaseDto.h"
#include "protocol/DeviceProtocolBase.h"

class DeviceBase : public QObject
{
    Q_OBJECT
public:
    explicit DeviceBase(QObject *parent = nullptr);

    QString getDevCode();
    QString getDeviceId();
    void setComName(QString comName);
    void setBaudRate(int baudRate);
    void setDevCode(QString devCode);
    void setDeviceId(QString deviceId);

    static DeviceBase * deviceFactory(QString deviceType, QObject * parent);

    void initSerialPort();
    bool isSerialOpen();
    virtual void sendDataToSerial(QByteArray data) = 0;
    virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0;
    virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0;

    virtual void mockReceivData() = 0;
    virtual void mockReceivCmdReply() = 0;

    DeviceProtocolBase * protocol;

protected:
    QString deviceId;
    QString devCode;
    QString comName;
    int baudRate;
    QString devType;

    QString commandId;
    QByteArray rawCommandBytes;

    QSerialPortUtil serialUtil;
    QSerialPortUtil serialUtilB; // serial port 2
    QKafkaProducer kafkaProducer;
    QByteArray dataBuff;
    QByteArray dataBuffB;
};

#endif // DEVICEBASE_H
