package com.seer.teach.teacher.service.platform;

import com.seer.teach.common.enums.AiPlatformEnum;
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平台调用服务工厂类
 * 用于根据平台获取对应的调用实现
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class AiPlatformCallServiceFactory {

    private final List<AiPlatformCallService> platformServices;
    private final Map<String, AiPlatformCallService> serviceMap = new ConcurrentHashMap<>();

    /**
     * 初始化服务映射
     */
    @PostConstruct
    public void init() {
        for (AiPlatformCallService service : platformServices) {
            serviceMap.put(service.getSupportedPlatform(), service);
            log.info("注册AI平台调用服务，平台: {}", service.getSupportedPlatform());
        }
    }

    /**
     * 根据平台获取对应的调用服务
     *
     * @param platform 平台编码
     * @return 对应的调用服务实现，如果未找到则返回null
     */
    public AiPlatformCallService getPlatformService(String platform) {
        return serviceMap.get(platform);
    }

    /**
     * 获取阿里云百炼平台调用服务
     *
     * @return 阿里云百炼平台调用服务
     */
    public AiPlatformCallService getAliyunBailianService() {
        return serviceMap.get(AiPlatformEnum.ALIYUN_BAILIAN.getCode());
    }

    /**
     * 获取火山引擎平台调用服务
     *
     * @return 火山引擎平台调用服务
     */
    public AiPlatformCallService getVolcEngineService() {
        return serviceMap.get(AiPlatformEnum.VOLC_ENGINE.getCode());
    }

    /**
     * 获取本地模型调用服务
     *
     * @return 本地模型调用服务
     */
    public AiPlatformCallService getLocalModelService() {
        return serviceMap.get(AiPlatformEnum.LOCAL.getCode());
    }
}