import axiosInstance from "@/apis/axios.config";
const SPEAKING_PREFIX = "/api/doubao"

const doubaoApis = {

    startChat:(userId: Number, assignmentId: Number, userQuestion: String, voiceCode: Number) =>{
        return axiosInstance.get(`${SPEAKING_PREFIX}/startChat`, {
            params: {
                userId,
                assignmentId,
                userQuestion,
                voiceCode
            }
        });
    },
    sendMessage:(userId: Number, assignmentId: Number, userQuestion: String, audioUrl: String, audioTime: Number, voiceCode: Number) => {
        return axiosInstance.get(`${SPEAKING_PREFIX }/sendMessage`, {
            params: {
                userId,
                assignmentId,
                userQuestion,
                audioUrl,
                audioTime,
                voiceCode
            },
            timeout: 60000 // AI 对话响应需要更长时间，设置为60秒
        });
    },

    endChat:(userId: Number, assignmentId: Number) =>{
        return axiosInstance.get(`${SPEAKING_PREFIX }/endChat`, {
            params: {
                userId,
                assignmentId
            }
        });
    },

    getChatHistory:(userId: Number, assignmentId: Number) =>{
        return axiosInstance.get(`${SPEAKING_PREFIX}/getChatHistory`, {
            params: {
                userId,
                assignmentId
            }
        });
    },

    deleteChatHistory:(userId : number, assignmentId: Number, userQuestion: String, voiceCode: Number) => {
        return  axiosInstance.delete(`${SPEAKING_PREFIX }/deleteChatHistory`, {
            params: {
                userId,
                assignmentId,
                userQuestion,
                voiceCode
            }
        });
    },

    saveSigment:(userId : number, assignmentId: Number, file: File, duration: Number) => {
        const formData = new FormData();
        formData.append('file',file);
        formData.append('userId', userId.toString());
        formData.append('assignmentId', assignmentId.toString());
        formData.append('duration', duration.toString());
        return  axiosInstance.post(`${SPEAKING_PREFIX }/saveSigment`, 
        formData,
        {
            headers:{
                'Content-Type': 'multipart/form-data'
            },
            timeout:300000
        });
    },
    getSigment:(userId : number, assignmentId: Number) => {
        return  axiosInstance.get(`${SPEAKING_PREFIX }/getSigment`, {
            params: {
                userId,
                assignmentId
            }
        });
    },

    getRecord:(userId : Number, assignmentId: Number) => {
        return  axiosInstance.get(`${SPEAKING_PREFIX }`, {
            params: {
                userId,
                assignmentId
            }
        });
    },

    getAudioScore:(userId: Number, assignmentId: Number, index: Number)=>{
        return axiosInstance.get(`${SPEAKING_PREFIX}/audioScore`, {
            params: {
                userId,
                assignmentId,
                index
            }
        })
    },
    getAudioSentiment:(userId: Number, assignmentId: Number, index: Number)=>{
        return axiosInstance.get(`${SPEAKING_PREFIX}/audioSentiment`, {
            params: {
                userId,
                assignmentId,
                index
            }
        })
    },
    getRestricData:(userId: Number, assignmentId: Number)=>{
        return axiosInstance.get(`${SPEAKING_PREFIX}/restrictData`, {
            params: {
                userId,
                assignmentId
            }
        })
    }




   
}

export default doubaoApis