package com.cmvr.test.flow.runtime.operator.llm;

import com.alibaba.fastjson2.JSONObject;
import com.cmvr.llm.service.LLMAiAgentPlatformService;
import com.cmvr.llm.service.LLMIntentRecognitionService;
import com.cmvr.test.enums.ActionEnum;
import com.cmvr.test.flow.runtime.message.TaskNodeExecuteMessage;
import com.cmvr.test.flow.runtime.message.TaskNodeExecuteResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service

@RequiredArgsConstructor
public class LLMAiAgentPlatformOperateService implements LLMOperateService {

    private final LLMAiAgentPlatformService llmAiAgentPlatformService;

    @Override
    public boolean supports(ActionEnum action) {
        return action.name().equals("AI_AGENT_PLATFORM");
    }

    @Override
    public TaskNodeExecuteResult execute(TaskNodeExecuteMessage message) {
        ActionEnum action = message.getAction();
        JSONObject inputParams = message.getInputParams();
        JSONObject config = inputParams.getJSONObject("config");
        String text = config.getString("text");
        String apiKey = config.getString("apiKey");
        Boolean invokeTts = inputParams.getBoolean("invokeTts");
        JSONObject output =llmAiAgentPlatformService.query(action.name(), text, apiKey, invokeTts, inputParams.getJSONObject("tts"));

        return TaskNodeExecuteResult.success(output);
    }
}