package cn.stylefeng.team.view.modular.parser.collect;

import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.rule.listener.ApplicationStartedListener;
import cn.stylefeng.team.view.api.ViewColumnParserCollector;
import cn.stylefeng.team.view.api.pojo.ParserDetail;
import cn.stylefeng.team.view.modular.parser.ParserContainer;
import org.springframework.boot.context.event.ApplicationStartedEvent;

import java.util.List;
import java.util.Map;

public class ParserCollectorListener extends ApplicationStartedListener {

    @Override
    public void eventCallback(ApplicationStartedEvent event) {
        Map<String, ViewColumnParserCollector> viewColumnParserCollectorMap = event.getApplicationContext().getBeansOfType(ViewColumnParserCollector.class);

        for (ViewColumnParserCollector value : viewColumnParserCollectorMap.values()) {
            List<ParserDetail> parserDetails = value.collectParser();
            if (ObjectUtil.isNotEmpty(parserDetails)) {
                for (ParserDetail parserDetail : parserDetails) {
                    ParserContainer.CONTAINER.put(parserDetail.getKey(), parserDetail);
                }
            }
        }
    }

}
