package com.sonic.frog.lib.client;

import com.alibaba.fastjson.TypeReference;
import com.sonic.common.AppRuntime;
import com.sonic.common.rpc.Result;
import com.sonic.common.rpc.RpcClient;
import com.sonic.frog.lib.output.AiInfoApiOutput;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

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

    private static final String GET_AI_INFO = "/api/ai/get-info";

    private RpcClient rpcClient;
    private String host;

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


    /**
     * 获取AI的基础信息
     * @param aiId
     * @return
     */
    public AiInfoApiOutput getAiInfo(Long aiId) {
        Map<String, Object> input = new HashMap<>();
        input.put("aiId", aiId);
        return rpcClient.post(host + GET_AI_INFO, input, new TypeReference<Result<AiInfoApiOutput>>(){});
    }

}
