package com.qingyun.service.agent;

import com.agentsflex.llm.deepseek.DeepseekConfig;
import com.agentsflex.llm.openai.OpenAILlmConfig;
import com.qingyun.service.domain.ContractModelConfig;

public class LlmStrategyFactory {

    public static LlmStrategy getStrategy(ContractModelConfig contractModelConfig) {
        if (contractModelConfig == null) {
            // 默认使用OpenAI
            return new OpenAILlmStrategy(defaultOpenAIConfig());
        }
        switch (contractModelConfig.getModelName().toLowerCase()) {
            case "openai":
                return new OpenAILlmStrategy(createOpenAIConfig(contractModelConfig));
            case "deepseek":
                return new DeepseekLlmStrategy(createDeepseekConfig(contractModelConfig));
            default:
                // 默认使用OpenAI
                return new OpenAILlmStrategy(createOpenAIConfig(contractModelConfig));
        }
    }


    private static OpenAILlmConfig createOpenAIConfig(ContractModelConfig contractModelConfig) {
        OpenAILlmConfig config = new OpenAILlmConfig();
        config.setEndpoint(contractModelConfig.getModelUrl());
        config.setModel(contractModelConfig.getModelVersion());
        config.setApiKey(contractModelConfig.getModelKey());
        return config;
    }

    private static DeepseekConfig createDeepseekConfig(ContractModelConfig contractModelConfig) {
        DeepseekConfig config = new DeepseekConfig();
        config.setEndpoint(contractModelConfig.getModelUrl());
        config.setModel(contractModelConfig.getModelVersion());
        config.setApiKey(contractModelConfig.getModelKey());
        return config;
    }

    private static OpenAILlmConfig defaultOpenAIConfig() {
        OpenAILlmConfig config = new OpenAILlmConfig();
        config.setEndpoint("http://10.77.149.156:11434");
        config.setModel("qwen3:30b-a3b");
        return config;
    }
}
