#ifndef PROJECTDIALOG_H
#define PROJECTDIALOG_H

#include <QComboBox>
#include <QDialog>
#include <QHash>
#include <QJsonArray>
#include <QJsonObject>

#include "../regex.h"
#include "hproject.h"

namespace Ui {
class ProjectDialog;
}

class ProjectDialog : public QDialog {
    Q_OBJECT

   public:
    explicit ProjectDialog(QWidget *parent = nullptr);
    ~ProjectDialog();
    void SetComboBoxBlast(const QJsonArray &bapoYuan);
    void SetComboBoxOperator(const QJsonArray &anQuanYuanArray);
    void SetL1AddressOptions(const QJsonArray &parentOptions);
    void setChildOptions(const QJsonArray &newChildOptions);
    void clearFormData();
    void setFormData(const HProject &Project);
    int getOperationStatus() const;
    void setOperationStatus(int newOperationStatus);

   private slots:
    void on_comboBoxAddr_currentIndexChanged(int index);

    void on_comboBoxAddr_2_currentIndexChanged(int index);

    void on_comboBoxOperator_currentIndexChanged(int index);

    void on_comboBoxBlast_currentIndexChanged(int index);

    void on_comboBoxAddr_3_currentIndexChanged(int index);

   signals:
    void validateDetNum(const QMap<QString, QString> &data);
    void validateDetNumUpdate(const QMap<QString, QString> &data);

   private:
    void fillComboBox(QComboBox *comboBox, const QJsonArray &jsonArray);
    void updateL2AddressOptions();
    void updateL3AddressOptions();
    void validateAndSaveProject();
    void SetComboBoxLora(const QString &grandChildName);
    void extractNames(const QJsonArray &array, QStringList &names);

   private:
    Ui::ProjectDialog *ui;
    QString blasterId;
    QString operatorId;
    QJsonArray blasterArray;
    QJsonArray operatorArray;
    QJsonArray dataOptions;
    QJsonArray parentOptions;
    QStringList loraOptions;
    QJsonArray childOptions;
    QJsonArray grandChildOptions;
    QJsonArray L1AddressOptions;
    QJsonArray L2AddressOptions;
    QJsonArray L3AddressOptions;
    QHash<QString, QString> nameLoraSnMap;
    int operationStatus;
};

#endif  // PROJECTDIALOG_H
