package cd.casic.plugin;

import cd.casic.framework.commons.util.spring.SpringUtils;
import org.pf4j.PluginState;
import org.pf4j.PluginWrapper;
import org.springframework.context.ApplicationEvent;

import java.nio.file.Path;
import java.util.List;

/**
 * @Author：mianbin
 * @Package：cd.casic.plugin
 * @Project：ops
 * @name：PluginManagerService
 * @Date：2024/03/18 14:46
 * @Filename：PluginManagerService
 * @description：插件基础安装类
 */
public interface PluginManagerService {
    /**
     * @param path 插件路径
     * @description 安装插件
     */
    PluginInfo install(Path path) throws Exception;

    /**
     * 安装插件后置操作
     *
     * @param pluginId pluginId
     */
    void installAfter(String pluginId);

    /**
     * @description 卸载插件
     */
    void unInstall(String pluginId, boolean isUpdate) throws Exception;

    /**
     * 启动插件
     *
     * @param pluginId
     * @return
     */
    PluginState startPlugin(String pluginId);

    /**
     * 停止插件
     *
     * @param pluginId pluginId
     * @return PluginState
     */
    PluginState stopPlugin(String pluginId);

    /**
     * @description 插件初始化
     */
    void initPlugins(List<PluginBean> plugins) throws Exception;

    /**
     * @description 获取所有插件
     */
    List<PluginWrapper> getInstallPlugins();


    default void sendPluginEvenet(ApplicationEvent applicationEvent) {
        SpringUtils.publishEvent(applicationEvent);
    }
}
