#pragma once

#include "esys_export.h"
#include <QObject>

namespace mpl {

class MPL_ESYS_API IPlugin : public QObject {
    Q_OBJECT

private:
    class IPluginPrivate* d_ptr;

public:
    enum class ShutdownFlag { SynchronousShutdown, AsynchronousShutdown };

    explicit IPlugin(QObject* parent = nullptr);
    virtual ~IPlugin();

    virtual bool initialize() = 0;
    virtual void extensionsInitialized() = 0;
    virtual bool delayedInitialize() { return false; }
    virtual ShutdownFlag aboutToShutdown() { return ShutdownFlag::SynchronousShutdown; }

    void addObject(QObject* obj);
    void addAutoReleasedObject(QObject* obj);
    void removeObject(QObject* obj);
    class PluginSpec* pluginSpec() const;

protected:
    void installPluginTranslator(QString plugin);

signals:
    void asynchronousShutdownFinished();

private:
    void setPluginSpec(PluginSpec* spec);
    friend class PluginSpecPrivate;
};

}
