package com.seer.teach.admin.service.impl;

import com.seer.teach.admin.service.AiModelCallStrategy;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import jakarta.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * AI模型调用策略工厂类
 * 用于根据场景编码获取对应的策略实现
 *
 * @author System
 * @since 2025-10-28
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class AiModelCallStrategyFactory {

    private final List<AiModelCallStrategy> strategies;
    private final Map<String, AiModelCallStrategy> strategyMap = new ConcurrentHashMap<>();

    /**
     * 初始化策略映射
     */
    @PostConstruct
    public void init() {
        for (AiModelCallStrategy strategy : strategies) {
            strategyMap.put(strategy.getSupportedScenarioCode(), strategy);
            log.info("注册AI模型调用策略，场景编码: {}", strategy.getSupportedScenarioCode());
        }
    }

    /**
     * 根据场景编码获取对应的策略
     *
     * @param scenarioCode 场景编码
     * @return 对应的策略实现，如果未找到则返回null
     */
    public AiModelCallStrategy getStrategy(String scenarioCode) {
        return strategyMap.get(scenarioCode);
    }
}