#pragma once

#include <functional>
#include <memory>
#include <string>

#include <softbus_core/plugin/IFramer.h>
#include <softbus_core/plugin/IParser.h>

namespace softbus::core {

class PluginLoader {
public:
    PluginLoader() = default;
    ~PluginLoader();

    PluginLoader(const PluginLoader&) = delete;
    PluginLoader& operator=(const PluginLoader&) = delete;

    bool load(const std::string& pluginPath);
    void unload();

    IFramer* framer() const { return framer_; }
    IParser* parser() const { return parser_; }
    bool isLoaded() const { return handle_ != nullptr; }

private:
    void* handle_{nullptr};
    IFramer* framer_{nullptr};
    IParser* parser_{nullptr};

    using CreateFramerFn = IFramer* (*)();
    using DestroyFramerFn = void (*)(IFramer*);
    using CreateParserFn = IParser* (*)();
    using DestroyParserFn = void (*)(IParser*);

    DestroyFramerFn destroyFramer_{nullptr};
    DestroyParserFn destroyParser_{nullptr};
};

} // namespace softbus::core
