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

import com.alibaba.fastjson2.JSONObject;
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 LLMIntentRecogOperateService implements LLMOperateService {

    private final LLMIntentRecognitionService intentRecognitionService;

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

    @Override
    public TaskNodeExecuteResult execute(TaskNodeExecuteMessage message) {
        ActionEnum action = message.getAction();
        JSONObject inputParams = message.getInputParams();
        String text = inputParams.getString("text");

        JSONObject output = intentRecognitionService.intentRecognition(action.name(), text);

        return TaskNodeExecuteResult.success(output);
    }
}