#ifndef BLASTPROJECTPAGE_H
#define BLASTPROJECTPAGE_H

#include <QJsonArray>
#include <QPushButton>
#include <QStandardItemModel>
#include <QWidget>

#include "../HttpClient.h"
#include "../PageWidget.h"
#include "../buttondelegate.h"
#include "../mqtt/mqttclient.h"
#include "hprojectdao.h"
#include "projectdialog.h"

namespace Ui {
class BlastProjectPage;
}

class BlastProjectPage : public QWidget {
    Q_OBJECT

   public:
    explicit BlastProjectPage(QWidget *parent = nullptr);
    ~BlastProjectPage();

   private slots:
    void PageChanged(int page);
    void onComboBoxIndexChanged(int index);
    void on_pushButton_clicked();
    void messageAndTopicReceived(const QByteArray &message, const QMqttTopicName &topic);
    void updateProjectUUId(QString uuid);

   private:
    void RefreshData();
    void loadDataFromSource(int currentPage, int pageSize);
    void personOptionsByType(const QJsonArray &arrayData);
    void addressOptions(const QJsonArray &jsonArray);
    void parseJsonString(const QJsonDocument &jsonDoc);
    void fillComboBox(QComboBox *comboBox, const QJsonArray &jsonArray);
    void insertPlan(const QMap<QString, QString> &data);
    void updateButtonClicked(const HProject &project);
    void updateProject(const QMap<QString, QString> &data);
    void deleteButtonClicked(const HProject &project);
    void extractNames(const QJsonArray &array, QStringList &names);

   private:
    Ui::BlastProjectPage *ui;
    PageWidget *pageWidget;
    ProjectDialog *dialog;
    HttpClient *m_httpClient;
    MqttClient *pcBC;
    HProjectDao dao;
    QJsonArray dataArray;
    QJsonArray dataArrayAddress;
    MqttClient *mqttClient;
    int pageSize;     // 每页显示的记录数量
    int currentPage;  // 当前页面
    int totalCount;
    int updateId;
};

#endif  // BLASTPROJECTPAGE_H
