#ifndef SENSORDIALOG_H
#define SENSORDIALOG_H

#include "httpclient.h"
#include "sensorlogs.h"
#include "sensorwidget.h"

#include <QDialog>

namespace Ui {
class SensorDialog;
}

class SensorDialog : public QDialog
{
    Q_OBJECT

public:
    explicit SensorDialog(QWidget *parent = nullptr,
                          SensorWidget *sensor = nullptr,
                          HttpClient *httpClient = nullptr);
    ~SensorDialog();

    enum DialogResult { NoSave = 0, SaveSuccess, SaveError };

signals:
    void resultReady(SensorDialog::DialogResult result);

protected:
    void closeEvent(QCloseEvent *event) override;

private:
    bool isSavingSuccess = false;
    HttpClient *_httpClient;
    SensorWidget *sensorWidget;
    SensorLogs sensorLogs;
    Sensor sensorC;
    SensorLogs sensorLogsC;

private:
    void onSaveButtonClicked();
    void onIsAlarmChanged(const QString &value);
    void onIsBooledChanged(const QString &value);
    void onIsVisibleChanged(const QString &value);
    void onNameChanged(const QString &value);
    void onUnitNameChanged(const QString &value);
    void onAlarmLowChanged(const QString &value);
    void onAlarmUpChanged(const QString &value);
    void onAlarmCooldownChanged(const QString &value);
    void onLogErrorChanged();
    void onLogManualChanged();
    void onAlarmSleepageChanged(const QString &value);
    void onLogHugeErrorChanged();

private:
    Ui::SensorDialog *ui;
};

#endif // SENSORDIALOG_H
