import { http } from '../http'
import { get } from '../request'

const languageSenseApi = {
  /**
   * 根据教材id查询例句
   */
  getSentenceById: (grade: number) => {
    return http.request({
      url: '/userSentenceLearn/sentence',
      timeout: 5000,
      method: 'POST',
      params: {
        grade,
      },
    })
  },

  /**
   * 根据教材id查询例句
   */
  getSentenceBySessionId: (sessionId: string) => {
    return http.request({
      url: `/userSentenceLearn/againLearn/${sessionId}`,
    })
  },

  /**
   * 保存每次答题记录
   */
  saveSentenceRecord: (data: anyObj) => {
    return http.request({
      url: '/userSentenceRecord/record',
      data,
      method: 'POST',
    })
  },

  /**
   * 保存一次练习的最终记录
   */
  saveSentenceRecordHistory: (data: anyObj) => {
    return http.request({
      url: '/userSentenceLearn/history',
      data,
      method: 'POST',
    })
  },

  /*
   **数据统计
   */
  // 根据时间维度获取统计数据
  queryStatByTimeFlag: (data: anyObj) =>
    http.request({
      url: '/userSentenceLearn/queryStatByTimeFlag',
      method: 'POST',
      data,
    }),

  // 获得语感阶段列表
  getSenseStagesApi: async (): Promise<any[]> => {
    return await get('/sysDictType/listSysDictData/grade_label')
  },
}

export default languageSenseApi
