#ifndef DEVICESETTINGSDIALOG_H
#define DEVICESETTINGSDIALOG_H

#include <QDialog>
#include <QEvent>
#include <QAbstractButton>
#include <QDialogButtonBox>
#include <QSpinBox>

class BoardIdHasBeenChanged : public QEvent
{
public:
  BoardIdHasBeenChanged(const short num, const short newId) : QEvent(QEvent::User) {_BoardNum = num; _BoardNewID = newId;}
 ~BoardIdHasBeenChanged() {}

  short BoardNum() const {return _BoardNum;}
  short BoardNewID() const {return _BoardNewID;}

private:
  short _BoardNum;
  short _BoardNewID;
};

class pollStatusChange : public QEvent
{
public:
  pollStatusChange(unsigned BoardID, bool Stat) : QEvent((QEvent::Type)1001) {_BoardID = BoardID; _Status = Stat;}
 ~pollStatusChange() {}

  unsigned BoardID() const {return _BoardID;}
  bool Status() const {return _Status;}

private:
  unsigned _BoardID;
  bool _Status;
};

namespace Ui {
class DeviceSettingsDialog;
}

class DeviceSettingsDialog : public QDialog
{
    Q_OBJECT

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

    unsigned currentBoardTimer(unsigned short _ID);
    unsigned currentSpeed();
    unsigned short currentParity();
    void updateSettingsAfterConnection(unsigned tmp_speed, unsigned tmp_parity, unsigned *tmp_adr, bool *ActiveDevices);
    void sendPollCommand(unsigned boardID, bool status);
    void updatePollStatus(unsigned boardID, bool status);
    void initPollForBoard(unsigned boardID, unsigned boardAdr);
    void onDisconnect();
signals:
    void parityChanged();
    void speedChanged();

    void firstBoardAdrHasBeenChanged();
    void secondBoardAdrHasBeenChanged();
    void thirdBoardAdrHasBeenChanged();
    void fourthBoardAdrHasBeenChanged();

private slots:

    void on_buttonApplyChangeTimer_clicked();

    void on_buttonApplyChangeSpeed_clicked();

    void on_buttonApplyChangeParity_clicked();

    void on_buttonApplyChangeAdr_clicked();

    void on_idComboBox_currentIndexChanged(int index);

    void on_buttonBox_clicked(QAbstractButton *button);

    void on_buttonApplyChangePoll_clicked();

    void on_idPollComboBox_currentIndexChanged(int index);

private:
    QSpinBox *_m_timer[4];
    unsigned _currentBoardTimers[4];
    unsigned _currentSpeed;
    unsigned short _currentParity;
    unsigned _currentAdrs[4];
    bool _currentPollStatus[4];

    Ui::DeviceSettingsDialog *ui;
};

#endif // DEVICESETTINGSDIALOG_H
