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

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

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

    private static final String GET_AI_CHT_INFO = "/api/ai-chat/info";
    private static final String UPDATE_IS_DEL_CHATTED = "/api/ai-chat/update-is-del-chatted";

    private RpcClient rpcClient;
    private String host;

    public AiChatInfoClient(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 AiChatInfoOutput getAiChatInfo(Long userId, Long aiId) {
        Map<String, Object> input = new HashMap<>();
        input.put("userId", userId);
        input.put("aiId", aiId);
        return rpcClient.post(host + GET_AI_CHT_INFO, input, new TypeReference<Result<AiChatInfoOutput>>() {
        });
    }

    /**
     * 更新是否删除聊天消息
     *
     * @return
     */
    public Void updateIsDelChatted(Long userId, List<Long> aiIdList) {
        Map<String, Object> input = new HashMap<>();
        input.put("userId", userId);
        input.put("aiIdList", aiIdList);
        return rpcClient.post(host + UPDATE_IS_DEL_CHATTED, input, new TypeReference<Result<Void>>() {
        });
    }

}
