import request from '@/utils/request'
import requestFile from '@/utils/requestfile'
import qs from 'qs'

/**
 * 在线考试试卷管理
 */

/**
 * page
 * size
 * 查询考试题库分类管理
 */
export function getExamLibraryCategory(params) {
  return request({
    url: 'api/onlineExamLibraryCategory',
    method: 'get',
    params
  })
}

/**
 * name     string
 * 在线考试题库分类
 */
export function postExamLibraryCategory(data) {
  return request({
    url: 'api/onlineExamLibraryCategory',
    method: 'post',
    data
  })
}

/**
 * name     string
 * 在线考试题库分类
 */
export function putExamLibraryCategory(data) {
  return request({
    url: 'api/onlineExamLibraryCategory',
    method: 'put',
    data
  })
}

/**
 * ids   []
 * 删除在线试题库分类
 */
export function deleteExamLibraryCategory(data) {
  return request({
    url: 'api/onlineExamLibraryCategory',
    method: 'delete',
    data
  })
}

/**
 * 题库管理
 */

/**
 * page
 * size
 * sort
 * 获取题库
 */
export function getExamLibrary(params) {
  return request({
    url: 'api/onlineExamLibrary/page',
    method: 'get',
    params
  })
}

/**
 * categoryId,
 * id: '',
 * name: '',
 * 新增题库
 */
export function postExamLibrary(data) {
  return request({
    url: 'api/onlineExamLibrary',
    method: 'post',
    data
  })
}

/**
 * categoryId,
 * id
 * name
 * 修改题库
 */
export function putExamLibrary(data) {
  return request({
    url: 'api/onlineExamLibrary',
    method: 'put',
    data
  })
}

/**
 * ids
 * 删除题库
 */
export function deleteExamLibrary(data) {
  return request({
    url: 'api/onlineExamLibrary',
    method: 'delete',
    data
  })
}

/**
 * difficulty 难度
 * exclusiveIds 排除的题目 id
 * libraryId 题库id
 * page
 * question 题干
 * size 每页显示的题目
 * sort 默认排序顺序为升序
 * type 单选题|多选题|判断题
 * 获取在线考试题
 */
export function getOnlineExamSubject(params) {
  const queryString = qs.stringify(params, {
    indices: false
  })
  console.log(params, queryString)
  return request({
    url: 'api/onlineExamSubject?' + queryString,
    method: 'GET'
  })
}

/**
 * analysis 答案分析
 * answer 答案[A|B|C|D] 多选题 A、B 判断题[对|错]
 * difficulty 难度[简单|一般|困难]
 * id id
 * libraryId 题库id
 * optiona 选项A
 * optionb 选项B
 * optionc 选项C
 * optiond 选项d
 * question 题干
 * type 类型[单选题|多选题|判断题]
 * 添加在线考试题
 */
export function postOnlineExamSubject(data) {
  return request({
    url: 'api/onlineExamSubject',
    method: 'POST',
    data
  })
}

/**
 * analysis 答案分析
 * answer 答案 单选题[A|B|C|D] 多选题 A、B 判断题 [对|错]
 * difficulty 难度 [简单|一般|困难]
 * id  id
 * libraryId  题库id
 * optiona  选项A
 * optionb  选项B
 * optionc  选项C
 * optiond  选项D
 * question 题干
 * type     类型[单选题|多选题|判断题]
 * 修改在线考试题
 */
export function putOnlineExamSubject(data) {
  return request({
    url: 'api/onlineExamSubject',
    method: 'PUT',
    data
  })
}

/**
 * 删除在线考试题
 */
export function deleteOnlineExamSubject(data) {
  return request({
    url: 'api/onlineExamSubject',
    method: 'DELETE',
    data
  })
}

/**
 * ids   []
 * 删除试卷
 */
export function deleteExamPaper(data) {
  return request({
    url: 'api/onlineExamPaper',
    method: 'delete',
    data
  })
}

/**
 * page  页码(0...N)
 * paperId  试卷Id
 * size  每页显示的数目
 * sort
 * type [单选题|多选题|判断题]
 * 在线考试： 查询题目
 */
export function findPaperSubject(params) {
  return request({
    url: 'api/onlineExamPaper/findSubject',
    method: 'get',
    params
  })
}


/**
 * name: 试卷名称
 * page: 页码
 * size: 每页显示的数目
 * sort: 以下列格式排序标准: property[,asc|desc]
 * 在线考试： 查询试卷
 */
export function findPagePager(data) {
  return request({
    url: 'api/onlineExamPaper/page',
    method: 'get',
    data
  })
}

/**
 * {
 *  addJudgementIds: [
 *    "paperId": 0,
 *    "subjectId": 0
 *  ],
 *  addMultipleChoiceIds: [
 *    "paperId": 0,
 *    "subjectId": 0
 *  ],
 *  addSingleChoiceIds: [
 *    "pagerId": 0,
 *    "subjectId": 0
 *  ],
 *  deleteJudgementIds: [
 *    "pagerId": 0,
 *    "subjectId": 0
 *  ],
 *  deleteMultipleChoiceIds: [
 *    "paperId": 0,
 *    "subjectId": 0
 *  ],
 *  deleteSingleChoiceIds: [
 *    "paperId": 0,
 *    "subjectId": 0
 *  ],
 *  paperId: 0
 * }
 * 智能组卷后手动编辑保存
 * */
export function savePaperAfterAutomatically(data) {
  return request({
    url: 'api/onlineExamPaper/saveAfterAutomatically',
    method: 'post',
    data
  })
}

/**
 * name
 * description
 * judgmentNum: 0
 * judgmentScore: 0
 * libraryIds: [],
 * mode: 生成方式 随机|简单|一般|困难
 * multipleChoiceNum: 0
 * multipleChoiceScore: 0
 * singleChoiceNum 单选题数量
 * singleChoiceScore 单选题分值
 * status 状态   [已发布|已关闭] 默认已关闭
 * 智能组卷
 */
export function savePaperAutomatically(data) {
  return request({
    url: 'api/onlineExamPaper/saveAutomatically',
    method: 'post',
    data
  })
}

/**
 * name
 * description
 * status [已关闭|已发布]
 * libraryIds: []
 * addJudgementIds: []
 * addMultipleChoiceIds: []
 * addSingleChoiceIds: []
 * singleChoiceScore
 * multipleChoiceScore
 * judgmentScore
 * 手动组卷
 */

export function saveManully(data) {
  return request({
    url: 'api/onlineExamPaper/saveManually',
    method: 'post',
    data
  })
}

export function changePaperStatus(data) {
  return request({
    url: 'api/onlineExamPaper/changeStatus',
    method: 'put',
    data
  })
}