import BaseAPI from '../base_api'

export default class ChapterAPI extends BaseAPI {
  /**
   * 获取章节列表信息
   * @param {[string]} cur_course_id -> cid
   * @param {[string]} cur_video_id -> vid
   */
  getChapterList = (cid, sid, vid) => this.get(`/ep/v2/education/courses/${cid}`, {})
  /**
   * 获取对应某个章节的详细信息
   * @param {[string]} vid
   */
  getCurrentChapterDetail = (vid) => this.post('/ep/v2/education/video-streaming', { vid })
  /**
   * 获取进度信息
   * @param {[string]} vid
   * @param {[string]} did
   */
  getProgress = (vid, did, sid) => this.get(`/ep/v2/education/video/${vid}/device`, { device_id: did })
  /**
   * 提交进度信息
   * @param {[object]} obj
   * d: obj.did,
      i: obj.did,
      c: obj.cid,
      s: obj.sid,
      v: obj.vid,
      _p: obj.pt, // 累计时间
      _m: obj.mpt, // 当前播放最大时间
      _c: obj.cpt // 当前播放位置
   */
  updateProgress = (obj = {}) => this.get('/ep/v2/analytics/upload-video', obj)
  /**
   * 获取试题信息
   * @param {[string]} eid
   */
  getExamDetail = (eid) => this.get(`/ep/v2/education/homeworks/${eid}`, {})
  /**
   * 提交考试信息
   * @param {[object]} param
   */
  submitExamDetail = (param) => this.post(`/ep/v2/education/homeworks`, param)
  /**
   * 获取对应 作业或问题 回答
   * @param {[string]} id resource_id
   */
  getHomework = (sid, id) => this.get(`/ep/v2/education/homeworks/${id}`, {})
  /**
   * 文件提交
   * @param {[object]} obj
   */
  uploadFile = (obj = {}) => this.post('/ep/util/upload-file', obj, { headers: { 'Content-Type': 'multipart/form-data' } })
  /**
   * 提交课程 作业或问题
   */
  updateHomework = (obj = {}) => this.post('/ep/v2/education/homeworks', obj, { headers: { 'Content-Type': 'multipart/form-data' } })
  /**
   * 获取对应 大作业 回答
   * @param {[string]} cid
   */
  getCourseHomework = (sid, cid) => this.get(`/ep/v2/education/courses/${cid}/essay`, {})
  /**
   * 提交课程 大作业
   * @param {[string]} cid
   */
  updateCourseHomework = (sid, cid, obj = {}) => this.post(`/ep/v2/education/courses/${cid}/essay`, obj, { headers: { 'Content-Type': 'multipart/form-data' } })
  /**
   * 提交 课程考核
   * @param {[string]} obj.cid
   * @param {[string]} obj.raw (base64)
   */
  updateSurveyAnswer = (obj) => this.post(`/ep/v2/education/survey/answer`, obj)
}
