#ifndef GLOBAL_H
#define GLOBAL_H

#include <QString>
#include <QSqlError>
#include <QVector>

enum DialogState
{
    DS_New,
    DS_Edit
};

struct DatabaseConfig
{
    QString strID; //存储在配置文件时用作唯一标识
    QString strConnectionName;
    QString strDBType; //"QPSQL","QMYSQL"...
    QString strHost;
    int     nPort;
    QString strDBName;
    QString strUserName;
    QString strPassword;
    bool    bSavePS;
    QString strComment;

    DatabaseConfig()
    {
        strConnectionName = "";
        strDBType = "QPSQL";
        strHost = "";
        nPort = 5432;
        strDBName = "postgres";
        strUserName = "";
        strPassword = "";
        bSavePS = true;
        strComment = "";
    }
};

struct AttributeGroup
{
    int id;
    QString name; //中文展示名称
    QString type; //英文标识名称
    QString remark;
    bool isPublic;

    //利用移动语义优化的构造函数(不定义也可以，QString实际上实现了隐式共享)
    AttributeGroup(int id, QString name, QString type, QString remark, bool isPublic)
        : id(id),
        name(std::move(name)),
        type(std::move(type)),
        remark(std::move(remark)),
        isPublic(isPublic){}
};

struct Model
{
    int id;
    QString name; //中文展示名称
    QString type; //英文标识名称
    QString remark;
    QVector<int> groups;

    Model(int id, QString name, QString type, QString remark, QVector<int> groups)
        : id(id),
        name(std::move(name)),
        type(std::move(type)),
        remark(std::move(remark)),
        groups(std::move(groups)){}

};


class DatabaseException : public std::runtime_error
{
public:
    explicit DatabaseException(const QSqlError& error)
        : std::runtime_error(error.text().toStdString()), m_error(error) {}

    QSqlError error() const { return m_error; }

private:
    QSqlError m_error;
};

#endif
