import axios from './config'

export const API_URL = 'https://pbl.cocorobo.cn/api/pbl/'
export const yweb_socket = 'wss://yjs.cocorobo.cn'
// export const yweb_socket = 'wss://yrs.cocorobo.cn'

/**
 * 获取课程详情
 * @param courseId 课程ID
 * @returns Promise<any>
 */
export const getCourseDetail = (courseId: string): Promise<any> => {
  return axios.get(`${API_URL}selectCourseDetail3`, {
    params: { courseId },
  })
}

/**
 * 获取课程详情
 * @param courseId 课程ID
 * @returns Promise<any>
 */
export const getPPTFile = (courseId: string, classid: string): Promise<any> => {
  return axios.get(`${API_URL}getPPTFile`, {
    params: { pptid: courseId, classid },
  })
}

/**
 * 提交作业接口
 * @param params 参数对象
 * @returns Promise<any>
 */
export interface SubmitWorkParams {
  uid: string
  cid: string
  stage: string
  task: string
  tool: string
  atool: string
  content: string
  type: string
}

export const submitWork = (params: SubmitWorkParams): Promise<any> => {
  return axios.post(`${API_URL}addCourseWorks_workPage`, [params])
}

/**
 * 查看作业接口
 * @param cid 课程ID
 * @param s s参数，传0
 * @param t 第几页幻灯片
 * @returns Promise<any>
 */
export const selectSWorks = (cid: string, s: string, t: string): Promise<any> => {
  return axios.get(`${API_URL}selectSWorks`, {
    params: {
      cid,
      s,
      t,
    },
  })
}

/**
 * 查看此课程作业需要上交的学生
 * @param oid 组织ID
 * @param cid 课程ID
 * @returns Promise<any>
 */
export const selectWorksStudent = (oid: string, cid: string): Promise<any> => {
  return axios.get(`${API_URL}selectWorksStudent`, {
    params: {
      oid,
      cid,
    },
  })
}

/**
 * 获取HTML内容
 * @param url 目标URL
 * @returns Promise<any>
 */
export const getHTML = (url: string, showError: boolean = false): Promise<any> => {
  return axios.get(`${url}`, { showError })
}

/**
 * 开启/关闭课程跟随模式
 * @param sopen 1否 2是
 * @param cid 课程ID
 * @returns Promise<any>
 */
export const updateCourseFollow = (sopen: number, cid: string): Promise<any> => {
  return axios.post(`${API_URL}updateCourseFollow`, [{
    sopen,
    cid,
  }])
}

/**
 * 新增：开启/关闭课程跟随模式（带第几张参数）
 * @param sopen 1否 2是
 * @param page 第几张
 * @param cid 课程ID
 * @returns Promise<any>
 */
export const updateCourseFollowC = (sopen: number, cid: string): Promise<any> => {
  return axios.post(`${API_URL}updateCourseFollowC`, [{
    sopen,
    cid,
  }])
}

/**
 * 查看课程跟随状态
 * @param cid 课程ID
 * @returns Promise<any>
 */
export const selectCourseSLook = (cid: string): Promise<any> => {
  return axios.get(`${API_URL}selectCourseSLook`, {
    params: { cid },
  })
}



/**
 * 
 * 获取用户数据
 * @param uid 用户id
 * @returns Promise<any>
 */

export const getUser = (uid: string): Promise<any> => {
  return axios.get(`${API_URL}getUser`, {
    params: { uid },
  })
}

/**
 * 
 * 存储对话内容
 * @param any 用户id
 * @returns Promise<any>
 */

export const insertChat = (params: any): Promise<any> => {
  return axios.post(`https://gpt4.cocorobo.cn/insert_chat`, params)
}

/**
 * 
 * 获取对话内容
 * @param any 用户id
 * @returns Promise<any>
 */

export const getChatList = (params: any): Promise<any> => {
  return axios.post(`https://gpt4.cocorobo.cn/get_agent_park_chat`, params)
}
/**
 * 
 * 获取对话内容
 * @param any 用户id
 * @returns Promise<any>
 */

export const getAgentData = (params: any): Promise<any> => {
  return axios.get(`https://appapi.cocorobo.cn/api/agents/agent/${params.id}`)
}
/**
 * 
 * 获取对话内容
 * @param any 用户id
 * @returns Promise<any>
 */

export const clearDialogue = (params: any): Promise<any> => {
  return axios.delete(`https://appapi.cocorobo.cn/api/agentchats/clear_thread_context`, { data: params })
}

/**
 * 
 * 获取作业·详细
 * @param any 作业id
 * @returns Promise<any>
 */

export const getWorkDetail = (params: any): Promise<any> => {
  return axios.get(`${API_URL}select_workPageById`, { params: params })
}








export default {
  getCourseDetail,
  getPPTFile,
  submitWork,
  selectSWorks,
  selectWorksStudent,
  getHTML,
  updateCourseFollow,
  updateCourseFollowC,
  selectCourseSLook,
  yweb_socket,
  getUser,
  insertChat,
  getChatList,
  getAgentData,
  clearDialogue,
  getWorkDetail
}

