package com.sonic.cow.lib.client;

import com.alibaba.fastjson.TypeReference;
import com.google.common.collect.Maps;
import com.sonic.common.AppRuntime;
import com.sonic.common.rpc.Result;
import com.sonic.common.rpc.RpcClient;
import com.sonic.cow.lib.input.VoiceTtsInput;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author code
 */
@Slf4j
@Service
public class VoiceClient {

    private static final String TTS_URL = "/api/tts";

    private RpcClient rpcClient;
    private String host;

    public VoiceClient(RpcClient rpcClient, AppRuntime appRuntime) {
        this.rpcClient = rpcClient;
        switch (appRuntime.getEnv()) {
            case dev:
                this.host = "http://dev-cow.svc.cloud";
                break;
            case local:
                this.host = "http://localhost:8080";
                break;
            case test:
                this.host = "http://test-cow-svc:8080";
                break;
            case product:
            default:
                this.host = "http://prod-cow-svc:8080";
        }
    }

    /**
     * 文本转语音
     *
     * @param voiceTtsInput
     * @return
     */
    public String tts(VoiceTtsInput voiceTtsInput) {
        return rpcClient.postBodySign(host + TTS_URL, voiceTtsInput, new TypeReference<Result<String>>() {
        });
    }

}
