import request from '@/utils/request'

// ============ 排水分区 ============
export function getPartitionPage(pageNum, pageSize, params) {
  return request({ url: '/api/drainage/partition/page', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function getPartitionById(id) {
  return request({ url: '/api/drainage/partition/' + id, method: 'get' })
}
export function getPartitionList() {
  return request({ url: '/api/drainage/partition/list', method: 'get' })
}
export function addPartition(data) {
  return request({ url: '/api/drainage/partition', method: 'post', data })
}
export function updatePartition(data) {
  return request({ url: '/api/drainage/partition', method: 'put', data })
}
export function deletePartition(id) {
  return request({ url: '/api/drainage/partition/' + id, method: 'delete' })
}
export function batchDeletePartition(ids) {
  return request({ url: '/api/drainage/partition/batch', method: 'delete', data: ids })
}

// ============ 排水管网 ============
export function getPipeNetworkPage(pageNum, pageSize, params) {
  return request({ url: '/api/drainage/pipeNetwork/page', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function addDrainagePipeNetwork(data) {
  return request({ url: '/api/drainage/pipeNetwork', method: 'post', data })
}
export function updateDrainagePipeNetwork(data) {
  return request({ url: '/api/drainage/pipeNetwork', method: 'put', data })
}
export function deleteDrainagePipeNetwork(id) {
  return request({ url: '/api/drainage/pipeNetwork/' + id, method: 'delete' })
}

// ============ 工程设施 ============
export function getFacilityPage(pageNum, pageSize, params) {
  return request({ url: '/api/drainage/facility/page', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function addFacility(data) {
  return request({ url: '/api/drainage/facility', method: 'post', data })
}
export function updateFacility(data) {
  return request({ url: '/api/drainage/facility', method: 'put', data })
}
export function deleteFacility(id) {
  return request({ url: '/api/drainage/facility/' + id, method: 'delete' })
}

// ============ 易积水点 ============
export function getWaterloggingPage(pageNum, pageSize, params) {
  return request({ url: '/api/drainage/waterlogging/page', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function addWaterlogging(data) {
  return request({ url: '/api/drainage/waterlogging', method: 'post', data })
}
export function updateWaterlogging(data) {
  return request({ url: '/api/drainage/waterlogging', method: 'put', data })
}
export function deleteWaterlogging(id) {
  return request({ url: '/api/drainage/waterlogging/' + id, method: 'delete' })
}

// ============ 监测设备管理 ============
export function getEquipmentPage(pageNum, pageSize, params) {
  return request({ url: '/api/drainage/equipment/base/page', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function getEquipmentById(id) {
  return request({ url: '/api/drainage/equipment/base/' + id, method: 'get' })
}
export function getEquipmentList() {
  return request({ url: '/api/drainage/equipment/base/list', method: 'get' })
}
export function addEquipment(data) {
  return request({ url: '/api/drainage/equipment/base', method: 'post', data })
}
export function updateEquipment(data) {
  return request({ url: '/api/drainage/equipment/base', method: 'put', data })
}
export function deleteEquipment(id) {
  return request({ url: '/api/drainage/equipment/base/' + id, method: 'delete' })
}
export function batchDeleteEquipment(ids) {
  return request({ url: '/api/drainage/equipment/base/batch', method: 'delete', data: ids })
}
export function getEquipmentTypeList() {
  return request({ url: '/api/drainage/equipment/type/list', method: 'get' })
}

// ============ 设备状态 ============
export function addEquipmentStatus(data) {
  return request({ url: '/api/drainage/equipment/status', method: 'post', data })
}
export function updateEquipmentStatus(data) {
  return request({ url: '/api/drainage/equipment/status', method: 'put', data })
}

// ============ 预警管理 ============

// 分页查询当前预警（今天的预警）
export function getWarningCurrentPage(pageNum, pageSize, params) {
  return request({
    url: '/api/drainage/warning/current/page',
    method: 'get',
    params: { pageNum, pageSize, ...params }
  })
}

// 分页查询历史预警
export function getWarningHistoryPage(pageNum, pageSize, params) {
  return request({
    url: '/api/drainage/warning/history/page',
    method: 'get',
    params: { pageNum, pageSize, ...params }
  })
}

// 查询预警详情
export function getWarningById(id) {
  return request({
    url: `/api/drainage/warning/${id}`,
    method: 'get'
  })
}

// 发布预警
export function addWarning(data) {
  return request({
    url: '/api/drainage/warning',
    method: 'post',
    data
  })
}

// 修改预警
export function updateWarning(data) {
  return request({
    url: '/api/drainage/warning',
    method: 'put',
    data
  })
}

// 更新预警状态
export function updateWarningStatus(id, data) {
  return request({
    url: `/api/drainage/warning/${id}/status`,
    method: 'put',
    params: data
  })
}

// 删除预警
export function deleteWarning(id) {
  return request({
    url: `/api/drainage/warning/${id}`,
    method: 'delete'
  })
}

// 发布预警（带人员）
export function publishWarning(data) {
  return request({
    url: '/api/drainage/warning/publish',
    method: 'post',
    data
  })
}

// 处理预警（指定人员处理，status 0→1）
export function firstApproveWarning(id, data) {
  return request({
    url: `/api/drainage/warning/${id}/firstApprove`,
    method: 'put',
    params: data
  })
}

// 审批预警（管理员审批，status 1→2）
export function finalApproveWarning(id, data) {
  return request({
    url: `/api/drainage/warning/${id}/finalApprove`,
    method: 'put',
    params: data
  })
}
