import request from '@/utils/request';

// 投放问卷
export function publishSurvey(data) {
  return request({
    url: `/console/survey_publishes`,
    method: 'post',
    data
  });
}

// 问卷详情
export function getSurveyInfo(sn) {
  return request({
    url: `/console/surveys/${sn}`,
    method: 'get'
  });
}

/**
 * 问题分析接口
 * @param sn
 * @param data {import('@/api/types/analysis.js').AnalysisParam}
 * @returns {Promise<axios.AxiosResponse<any>> | *}
 */
export function surveyAnalysis(sn, data = {}) {
  return request({
    url: `/console/surveys/${sn}/chart_analysis`,
    method: 'post',
    data
  });
}

// 查看二维码
export function getQrcode(sn) {
  return request({
    url: `/console/survey_publishes/${sn}/qrcode`,
    method: 'get'
  });
}

// 获取问卷测试是否弹层
export function getCheckSurvey(sn) {
  return request({
    url: `/console/check_survey_test/${sn}`,
    method: 'get'
  });
}

/* 获取问题列表 */
export function getQuestionList(params, code) {
  return request({
    headers: {
      'survey-invite-code': code || ''
    },
    url: `/console/surveys/${params}/questions`,
    method: 'get'
  });
}

/* 取消投放 */
export function modify(params, code) {
  return request({
    headers: {
      'survey-invite-code': code || ''
    },
    url: `/console/question/publish/modify`,
    method: 'POST'
  });
}

export function finish(sn, code) {
  return request({
    headers: {
      'survey-invite-code': code || ''
    },
    url: `/console/surveys/${sn}/finish`,
    method: 'PATCH'
  });
}
