#ifndef COUNTERWINDOWRT_H
#define COUNTERWINDOWRT_H

#include <QWidget>
#include <QLabel>
#include <QTimer>
#include <QDate>
#include <QTime>
#include <QFile>
#include <QThread>
#include <QMessageBox>

#include "CounterDevice.h"
#include "CounterChannel.h"
#include "QLabelDblClick.h"
#include "ChannelChartForm.h"
#include "CounterSettingForm.h"
#include "common/utils/SettingConfig.h"
#include "common/utils/TimerCounterUtil.h"
#include "common/HttpRequestController.h"
#include "common/utils/QKafkaConsumer.h"

QT_BEGIN_NAMESPACE
namespace Ui { class CounterWindowRT; }
QT_END_NAMESPACE

class CounterWindowRT : public QWidget
{
    Q_OBJECT

public:
    CounterWindowRT(QWidget *parent = nullptr);
    ~CounterWindowRT();

public slots:
    void keyPressEvent(QKeyEvent *event);

    void onChannelSettingSubmit(QJsonArray channelSettings);

private:
    Ui::CounterWindowRT *ui;

    CounterSettingForm * settingForm;

    QVector<QLabel *> devTitleList; // 计数器设备标题的QLabel集合
    QVector<QLabel *> devRefList; // Ref通道
    QVector<QLabel *> channelNameList; // 通道名的QLabel集合
    QVector<QLabel *> channelValueList; // 通道测量值的QLabel集合

    HttpRequestController * httpReq;
    QKafkaConsumer * kafkaConsumer;

    int initHttpToken();
    void getDeviceList();
    void getChannelList(QString deviceId);

    void initDevAndChannelForm(int count);
    void updateChannelDataForm(QJsonArray messageArray);
    void updateDeviceAlarm(QJsonArray alarmList);

    CounterChannel * getChannelByDevAndId(QString deviceId, QString channelId);

private slots:
    void updateDateAndTime();

    void on_btnMenuMin_clicked();
    void on_btnMenuSetting_clicked();

    void initChannelForm();
    void updateDeviceWidget();

    void onChannelNameLabelDblClicked();
    void drawCounterDataOnPage(QJsonArray messageArray);

    void onKafkaMessageReceived(QJsonObject message);

//    void queryClockAlarmOnTime();
//    void onAlarmChanged();
};
#endif // COUNTERWINDOWRT_H
