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

import com.alibaba.fastjson2.JSONObject;
import com.cmvr.llm.service.LLMAiTtsService;
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 LLMAiTtsOperateService implements LLMOperateService {

    private final LLMAiTtsService llmAiTtsService;

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

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

        JSONObject output = llmAiTtsService.play(url, text, voice, speed, volume);

        return TaskNodeExecuteResult.success(output);
    }
}