import request from "@/utils/request"

/** 分页列表 */
export function listVaccinationData(query) {
  return request({
    url: "/dataModel/vaccinationData/list",
    method: "get",
    params: query
  })
}

/** 详情 */
export function getVaccinationData(id) {
  return request({
    url: "/dataModel/vaccinationData/" + id,
    method: "get"
  })
}

/** 新增 */
export function addVaccinationData(data) {
  return request({
    url: "/dataModel/vaccinationData",
    method: "post",
    data
  })
}

/** 修改 */
export function updateVaccinationData(data) {
  return request({
    url: "/dataModel/vaccinationData",
    method: "put",
    data
  })
}

/** 删除 */
export function delVaccinationData(ids) {
  return request({
    url: "/dataModel/vaccinationData/" + ids,
    method: "delete"
  })
}

/** 可选年份 */
export function listVaccinationDataYearOptions() {
  return request({
    url: "/dataModel/vaccinationData/yearOptions",
    method: "get"
  })
}

/** 可选月份（1～12） */
export function listVaccinationDataMonthOptions() {
  return request({
    url: "/dataModel/vaccinationData/monthOptions",
    method: "get"
  })
}

/** 乡镇下拉 */
export function listVaccinationDataTownOptions() {
  return request({
    url: "/dataModel/vaccinationData/townOptions",
    method: "get"
  })
}

/** 县→乡镇→村树 */
export function listVaccinationDataVillageTree() {
  return request({
    url: "/dataModel/vaccinationData/villageTree",
    method: "get"
  })
}

/** Excel 导入 */
export function importVaccinationData(file, statYear, statMonth) {
  const formData = new FormData()
  formData.append("file", file, file.name)
  formData.append("statYear", String(statYear))
  formData.append("statMonth", String(statMonth))
  return request({
    url: "/dataModel/vaccinationData/importData",
    method: "post",
    headers: {
      repeatSubmit: false
    },
    data: formData
  })
}

/** 下载导入模板（GET） */
export function downloadVaccinationDataTemplate() {
  return request({
    url: "/dataModel/vaccinationData/importTemplate",
    method: "get",
    responseType: "blob"
  })
}

/**
 * 按年月导出（GET）
 * @param {number} statYear
 * @param {number} statMonth
 * @param {number} [townDeptId] 可选乡镇
 */
export function exportVaccinationData(statYear, statMonth, townDeptId) {
  const params = { statYear, statMonth }
  if (townDeptId != null && townDeptId !== "") {
    params.townDeptId = townDeptId
  }
  return request({
    url: "/dataModel/vaccinationData/export",
    method: "get",
    params,
    responseType: "blob"
  })
}
