package cd.casic.plugin.core.register;

import cd.casic.plugin.dataobject.pojo.PluginInfo;
import cd.casic.plugin.function.IPluginProcessor;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @description: TODO
 * @author: mianbin
 * @date: 2025/5/22 20:19
 * @version: 1.0
 */
@Slf4j
@Component
public class StartPluginManagerProcessor implements IPluginProcessor {

    @Resource
    private List<IPluginProcessor> iPluginProcessors;

    @Override
    public void initialize() throws Exception {
        iPluginProcessors.stream().forEach(var -> {
            try {
                var.initialize();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
    }

    @Override
    public void registry(PluginInfo plugin) throws Exception {
        iPluginProcessors.stream().forEach(var -> {
            try {
                var.registry(plugin);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
    }

    @Override
    public void unRegistry(PluginInfo plugin) throws Exception {
        iPluginProcessors.stream().forEach(var -> {
            try {
                var.unRegistry(plugin);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
    }
}
