#ifndef SQLITEEXTENSIONMANAGER_H
#define SQLITEEXTENSIONMANAGER_H

#include "core_global.h"
#include "letos.h"
#include <QSharedPointer>
#include <QObject>
#include <QCoreApplication>

class API_EXPORT SqliteExtensionManager : public QObject
{
    Q_OBJECT

    public:
        struct API_EXPORT Extension
        {
            QString filePath;
            QString initFunc;
            QStringList databases;
            bool allDatabases = true;

            QString getResolvedPath() const
            {
                return resolvePath(filePath);
            }
        };

        typedef QSharedPointer<Extension> ExtensionPtr;

        virtual void setExtensions(const QList<ExtensionPtr>& newExtensions) = 0;
        virtual QList<ExtensionPtr> getAllExtensions() const = 0;
        virtual QList<ExtensionPtr> getExtensionForDatabase(const QString& dbName) const = 0;
        virtual QStringList getExtensionDirs() const = 0;
        virtual void loadFromConfig() = 0;
        virtual void init() = 0;

        static QString resolvePath(QString path)
        {
            return path.replace(APP_PATH_PREFIX, QCoreApplication::applicationDirPath());
        }

        inline static const QString APP_PATH_PREFIX = QStringLiteral("{APP_PATH}");

    signals:
        void extensionListChanged();
};

#define SQLITE_EXTENSIONS LETOS->getSqliteExtensionManager()

#endif // SQLITEEXTENSIONMANAGER_H
