#pragma once

#include <memory>

#include <QHash>
#include <QString>

#include "core/plugin_system/PluginManager.h"

namespace softbus::core::plugin_system
{

class PluginHost
{
public:
    struct LoadedPlugin
    {
        QString path;
        QString protocolPluginId;
        QString framerPluginId;
        QString mapperPluginId;
        int abiVersion{1};
        void* handle{nullptr};
    };

    explicit PluginHost(std::shared_ptr<PluginManager> manager);
    ~PluginHost();

    bool loadPlugin(const QString& path, QString* err = nullptr);
    bool reloadPlugin(const QString& path, QString* err = nullptr);
    bool unloadPlugin(const QString& path, QString* err = nullptr);

private:
    void unloadAll();

    std::shared_ptr<PluginManager> m_manager;
    QHash<QString, LoadedPlugin> m_loaded;
};

} // namespace softbus::core::plugin_system
