import request from "@/utils/request"

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

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

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

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

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

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

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

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

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

/** Excel 导入 */
export function importLargeLivestockFarmer(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/largeLivestockFarmer/importData",
    method: "post",
    headers: {
      repeatSubmit: false
    },
    data: formData
  })
}

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

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