#pragma once

#include <QSqlDatabase>
#include <QString>
#include <QMutex>
#include <QThread>

class DatabaseManager
{
public:
    static DatabaseManager& instance();
    ~DatabaseManager();

    bool initialize(const QString& databasePath = QString());
    // Returns a connection owned by the calling thread. SQLite/Qt database
    // connections must never be shared across threads.
    QSqlDatabase database();

private:
    DatabaseManager();
    Q_DISABLE_COPY(DatabaseManager)

    QSqlDatabase m_db;
    QMutex m_mutex;
    QString m_databasePath;
    Qt::HANDLE m_ownerThread{nullptr};
    bool m_initialized{false};
};
