package cd.casic.plugin.function;

import cd.casic.plugin.dataobject.pojo.PluginInfo;
import cd.casic.plugin.dataobject.dto.PluginInformation;
import org.pf4j.PluginState;
import org.pf4j.PluginWrapper;
import org.springframework.core.io.Resource;
import org.springframework.core.io.buffer.DataBuffer;

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

/**
 * @Classname PluginService
 * @Description 插件服务类
 * @Date 2025/5/8 19:58
 * @Created by mianbin
 */
public interface IPluginManager {

    /**
     * @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<PluginInformation> plugins) throws Exception;

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


    PluginInfo upgrade(String name, Path path);

    /**
     * 重新加载插件，插件spec.enabled 设置为 true
     */
    PluginInfo reload(String name);

    DataBuffer uglifyJsBundle();

    DataBuffer uglifyCssBundle();

    String generateBundleVersion();

    Resource getJsBundle(String version);

    Resource getCssBundle(String version);

    PluginInfo changeState(String pluginName, boolean requestToEnable, boolean wait);

}
