package com.ch.jedge.jbot.intent.bot;

import com.ch.jedge.jbot.intent.JedgeJBotCBService;
import com.changhong.jedge.JMgbusClient;
import com.changhong.jedge.JMgbusModual;

import java.lang.reflect.Constructor;

import static com.ch.jedge.jbot.JEJBotLLMConst.sval_default_llm_call_service;


public class JBotAppClient extends JMgbusClient {

    static private JBotAppClient jLlmBot;

    public JBotAppClient(String subnet, String mgc_name, int threadCount, boolean tryLocal) {
        super(subnet, mgc_name, threadCount, tryLocal);
    }

    public static JBotAppClient getInstance(String botName, Class<? extends JedgeJBotCBService> serviceCls) {
        if(jLlmBot == null) {
            jLlmBot = new JBotAppClient("#0", botName, 10, true);
            try {
                Constructor<? extends JedgeJBotCBService> constructor = serviceCls.getConstructor(JMgbusModual.class);
                JedgeJBotCBService service = constructor.newInstance(jLlmBot);
                jLlmBot.bindService(sval_default_llm_call_service, service);
            }catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
        return jLlmBot;
    }

}
