#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSqlError>
#include "global.h"
#include "messageDialog.h"

class DatabaseManager;
class ConnectionDialog;
class DBStructureView;
class DBStructureModel;
class ModelInfoEditDialog;

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

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

    void showMessageDialog(MessageDialogType,const QString&,const QString&);
    void hideMessageDialog();
    const QString getCurConnection();

protected:
    bool eventFilter(QObject*, QEvent*) override;

private:
    void initialize();

    Ui::MainWindow *ui;
    DatabaseManager* m_dbManager;
    QSqlError m_lastSqlError;
    MessageDialog* m_pMessageDialog;
    ConnectionDialog* m_pConnectionDialog;
    DBStructureView* m_pDBStrutureView;
    DBStructureModel* m_pDBStrutureModel;
    ModelInfoEditDialog* m_pModelInfoDialog;

private slots:
    void onActionTrigger_connect();
    void onActionTrigger_disconnect();
    void onActionTrigger_addModel();
    void onActionTrigger_removeModel();

    void onSIG_addConnection(DatabaseConfig&);
    void onSIG_errorFromDBManger(const QString& strConnectionName, const QSqlError& error);
    void onSIG_errorFormSQLExecutor(const QString& error);
    void onSIG_connectionStatusChanged(const QString& strConnectionName, bool bConnected);
    void onSIG_addModel(Model&);
};

#endif // MAINWINDOW_H
