package com.easyproject.common.utils.coze;

import com.coze.openapi.service.auth.TokenAuth;
import com.coze.openapi.service.config.Consts;
import com.coze.openapi.service.service.CozeAPI;
import lombok.extern.slf4j.Slf4j;

/**
 * 方法说明: AI对话-coze平台
 */
@Slf4j
public class ChatAiForCozeUtils {

    private static CozeAPI cozeClient = null; // 缓存客户端实例
    private static String cachedToken = null; // 缓存 token


    /**
     * 方法说明: 初始化或获取已初始化的coze客户端
     * @param token 个人认证Token
     * @return CozeAPI 客户端实例
     */
    public static CozeAPI getCozeClient(String token) {
        if (cozeClient == null || !token.equals(cachedToken)) {
            log.info("初始化coze客户端实例");
            synchronized (ChatAiForCozeUtils.class) {
                if (cozeClient == null || !token.equals(cachedToken)) {
                    TokenAuth authCli = new TokenAuth(token);
                    cozeClient = new CozeAPI.Builder()
                            .baseURL(Consts.COZE_CN_BASE_URL)
                            .auth(authCli)
                            .readTimeout(5*60*1000)
                            .build();
                    cachedToken = token;
                }
            }
        }
        return cozeClient;
    }


    /**
     * 方法说明: 语音转文字
     * @param
     * @return
     * @author java-101
     * @date 2025-04-02 11:48:21
     */
    public static String getApiUrlTranscriptions(){
        return "https://api.coze.cn/v1/audio/transcriptions";
    }

    /**
     * 方法说明: 文字转语音
     * @param
     * @return
     * @author java-101
     * @date 2025-04-02 11:48:00
     */
    public static String getApiUrlSpeech(){
        return "https://api.coze.cn/v1/audio/speech";
    }

    /**
     * 方法说明: 知识库-查询只看文件
     * @param
     * @return
     * @author java-101
     * @date 2025-04-02 11:45:39
     */
    public static String getKnowledgeDocumenList(){
        return "https://api.coze.cn/open_api/knowledge/document/list";
    }

    /**
     * 方法说明: 智能体-获取智能体信息
     * @param
     * @return
     * @author java-101
     * @date 2025-04-07 23:33:37
     */
    public static String getBotInfoUrl(){
        return "https://api.coze.cn/v1/bot/get_online_info";
    }
}