package tech.easyflow.ai.config;

import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import tech.easyflow.ai.mapper.BotCategoryMapper;
import tech.easyflow.common.util.SpringContextUtil;
import tech.easyflow.common.dict.DictManager;
import tech.easyflow.common.dict.loader.DbDataLoader;

import javax.annotation.Resource;

/**
 * 注册仍由 Bot 兼容页面使用的数据库字典。
 */
@Configuration
public class AiDictAutoConfig {

    /** Bot 分类字典数据访问器。 */
    @Resource
    private BotCategoryMapper botCategoryMapper;

    /**
     * 应用启动完成后注册 Bot 兼容字典。
     */
    @EventListener(ApplicationReadyEvent.class)
    public void onApplicationStartup() {

        DictManager dictManager = SpringContextUtil.getBean(DictManager.class);
        dictManager.putLoader(new DbDataLoader<>("aiBotCategory", botCategoryMapper, "id", "category_name", null, null, false));

    }
}
