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.GenAiUserContentV1Input;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

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

    private static final String GEN_SUP_CONTENT_URL = "/api/gen/sup-content";
    private static final String GEN_USER_CONTENT_URL = "/api/gen/user-content";


    private RpcClient rpcClient;
    private String host;

    public ContentClient(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 userId
     * @param aiId
     * @return
     */
    public List<String> genSupContent(Long userId, Long aiId) {
        Map<Object, Object> params = Maps.newHashMap();
        params.put("userId", userId);
        params.put("aiId", aiId);
        return rpcClient.postBodySign(host + GEN_SUP_CONTENT_URL, params, new TypeReference<Result<List<String>>>() {
        });
    }

    /**
     * 一键生成
     * @param input
     * @return
     */
    public String genUserContent(GenAiUserContentV1Input input) {
        return rpcClient.postBodySign(host + GEN_USER_CONTENT_URL, input, new TypeReference<Result<String>>() {
        });
    }


}
