import axios from "axios"
import store from "@/store/index.js"

export default {
  async getAnswerRecord() {
    const lastToken = localStorage.getItem('token')
    const res = await axios({
      method: 'get',
      url: `${process.env.VUE_APP_API_PREFIX}/api/cms/question/getListByUser`,
      headers: {
        token: lastToken,
      }
    })
    return res.data.data
  },
  async submitAnswer(isCorrect, id, selectedOptions, badgeType) {
    const lastToken = localStorage.getItem('token')
    const res = await axios({
      method: 'post',
      url: `${process.env.VUE_APP_API_PREFIX}/api/cms/question/submit`,
      headers: {
        token: lastToken,
      },
      data: {
        hasRight: isCorrect,
        num: id,
        options: JSON.stringify(selectedOptions),
        type: badgeType.join(','),
      }
    })
    return res.data.data
  },
}