import request from "@/utils/request"

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

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

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

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

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

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

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

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

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

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

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

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