import { request } from '../request'

/** 获取所有题目列表 */
export function fetchGetQuestionListAll() {
  return request<Api.Question.CommonRecord>({
    url: '/Base/ActivityMain/GetQuestionListAll',
    method: 'get',
  })
}

/** 新增题目 */
export function fetchAddQuestion(data?: Api.Question.AddParams) {
  return request<Api.Question.CommonRecord>({
    url: '/Base/ActivityMain/AddBase_QuestionList',
    method: 'post',
    data: data || {},
  })
}

/** 更新题目 */
export function fetchUpdateQuestion(data?: Api.Question.AddParams) {
  return request<Api.Question.CommonRecord>({
    url: '/Base/ActivityMain/UpdateQuestionList',
    method: 'post',
    data: data || {},
  })
}

/** 删除题目 */
export function fetchDeleteQuestion(id: number) {
  return request<Api.Question.CommonRecord>({
    url: `/Base/ActivityMain/DeleteQuestionList/?Id=${id}`,
    method: 'post',
  })
}

/** 获取所有问题库列表(分页) */
export function fetchGetQuestionLibraryListAll(params: Api.Question.GetQuestionLibraryListAllParams) {
  return request<Api.Question.CommonRecord>({
    url: '/Base/ActivityMain/GetQuestionListDetail',
    method: 'get',
    params: {
      QuestionId: params.questionId,
      PageIndex: params.pageIndex,
      PageSizes: params.pageSizes,
      keyWords: params.keyWords,
    },
  })
}

/** 新增一条问题库 */
export function fetchAddQuestionLibrary(params: Api.Question.AddQuestionLibraryParams, file?: File | null) {
  const formData = new FormData()
  if (file) {
    formData.append('Image', file)
  }
  return request<Api.Question.CommonRecord>({
    url: '/Base/ActivityMain/AddQuestionListDetail',
    method: 'post',
    params: {
      QuestionId: params.questionId,
      Name: params.name,
      Answer: params.answer,
      Type: params.type,
      IsGood: params.IsGood,
      ImageUrl: params.imageUrl,
    },
    data: formData,
  })
}

/** 更新一条问题库 */
export function fetchUpdateQuestionLibrary(params: Api.Question.AddQuestionLibraryParams, file?: File | null) {
  const formData = new FormData()
  if (file) {
    formData.append('Image', file)
  }
  return request<Api.Question.CommonRecord>({
    url: '/Base/ActivityMain/UpdateQuestionListDetail',
    method: 'post',
    params: {
      Id: params.id,
      QuestionId: params.questionId,
      Name: params.name,
      Answer: params.answer,
      Type: params.type,
      IsGood: params.IsGood,
      ImageUrl: params.imageUrl,
    },
    data: formData,
  })
}

/** 删除一条问题库 */
export function fetchDeleteQuestionLibrary(ids: number[]) {
  return request({
    url: `/Base/ActivityMain/DeleteQuestionListDetail`,
    method: 'post',
    data: ids,
  })
}
