package com.seer.teach.teacher.service.registry.smartRead;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

@Slf4j
@Component
public class SmartReadRegistry {

    private final Map<Integer, SmartReadHandler> handlerMap = new HashMap<>();

    @Autowired
    public SmartReadRegistry(List<SmartReadHandler> handlers) {
        for (SmartReadHandler handler : handlers) {
            Integer type = handler.getType();
            if (handlerMap.containsKey(type)) {
                log.warn("重复注册智能听书模块处理器 type={}", type);
            }
            handlerMap.put(type, handler);
            log.info("注册智能听书模块处理器 type={} -> {}", type, handler.getClass().getSimpleName());
        }
    }

    public SmartReadHandler getHandler(Integer type) {
        return handlerMap.get(type);
    }
}
