import request from '@/utils/request'

const get = (url, params) => request({ url, method: 'get', params })

export const listFlowMonitoring = (params) => get('/waterSupply/monitoring/flow/page', params)
export const getFlowTrend = (id, params) => get(`/waterSupply/monitoring/flow/trend/${id}`, params)
export const exportFlowMonitoring = (params) => request({ url: '/waterSupply/monitoring/flow/export', method: 'get', params, responseType: 'blob' })

export const listPressureMonitoring = (params) => get('/waterSupply/monitoring/pressure/page', params)
export const getPressureTrend = (id, params) => get(`/waterSupply/monitoring/pressure/trend/${id}`, params)
export const exportPressureMonitoring = (params) => request({ url: '/waterSupply/monitoring/pressure/export', method: 'get', params, responseType: 'blob' })

export const listLeakageMonitoring = (params) => get('/waterSupply/monitoring/leakage/page', params)
export const getLeakageTrend = (id, params) => get(`/waterSupply/monitoring/leakage/trend/${id}`, params)
export const exportLeakageMonitoring = (params) => request({ url: '/waterSupply/monitoring/leakage/export', method: 'get', params, responseType: 'blob' })

export const getAlarmStats = () => get('/waterSupply/alarm/stats')
export const listRealtimeAlarms = () => get('/waterSupply/alarm/realtime')
export const listAlarmHistory = (params) => get('/waterSupply/alarm/history', params)
export const getAlarmDetail = (id) => get(`/waterSupply/alarm/detail/${id}`)
export const resolveAlarm = (id, handleRemark) => request({ url: `/waterSupply/alarm/resolve/${id}`, method: 'put', params: { handleRemark } })
export const dispatchAlarm = (data) => request({ url: '/waterSupply/alarm/dispatch', method: 'post', data })
export const auditAlarm = (data) => request({ url: '/waterSupply/alarm/audit', method: 'post', data })
export const listAlarmAudits = (alarmId) => get('/waterSupply/alarm/audit/list', { alarmId })
export const getAlarmFlow = (id) => get(`/waterSupply/alarm/flow/${id}`)
export const listAlarmMapPoints = () => get('/waterSupply/alarm/map/points')

export const listThresholds = (params) => get('/waterSupply/alarm/threshold/page', params)
export const getThreshold = (id) => get(`/waterSupply/alarm/threshold/detail/${id}`)
export const saveThresholds = (data) => request({ url: '/waterSupply/alarm/threshold/save', method: 'post', data })
export const updateThreshold = (data) => request({ url: '/waterSupply/alarm/threshold/update', method: 'put', data })
export const deleteThresholds = (ids) => request({ url: '/waterSupply/alarm/threshold/delete', method: 'delete', params: { ids } })

export const listDeviceLedger = (params) => get('/waterSupply/device/ledger/page', params)
export const getDeviceTypeStatistics = () => get('/waterSupply/device/ledger/typeStatistics')
export const listDeviceGisPoints = (params) => get('/waterSupply/device/ledger/gisPoints', params)
export const exportDeviceLedger = (params) => request({ url: '/waterSupply/device/ledger/export', method: 'post', params })
export const listAbnormalDevices = (params) => get('/waterSupply/device/abnormal/page', params)
export const listAbnormalGisPoints = (params) => get('/waterSupply/device/abnormal/gisPoints', params)
export const exportAbnormalDevices = (params) => request({ url: '/waterSupply/device/abnormal/export', method: 'post', params })
export const createMaintainOrder = (data) => request({ url: '/waterSupply/device/maintain/order', method: 'post', data })
export const createAbnormalOrder = (data) => request({ url: '/waterSupply/device/abnormal/order', method: 'post', data })
export const listMaintainRecords = (params) => get('/waterSupply/device/maintain/record/page', params)
export const saveMaintainRecord = (data) => request({ url: '/waterSupply/device/maintain/record', method: 'post', data })
export const updateMaintainRecord = (data) => request({ url: '/waterSupply/device/maintain/record', method: 'put', data })
export const deleteMaintainRecord = (id) => request({ url: `/waterSupply/device/maintain/record/${id}`, method: 'delete' })

export const getPipeNetworkDashboard = (params) => get('/waterSupply/pipeNetwork/statistics/dashboard', params)
export const exportPipeNetworkStatistics = (params) => request({ url: '/waterSupply/pipeNetwork/statistics/export', method: 'get', params, responseType: 'blob' })
export const getWaterFacilityFeatures = (params) => get('/waterSupply/gis/map/features', params)
export const getWaterFacilityOverview = () => get('/waterSupply/gis/map/overview')
export const getWaterFacilityDetail = (type, id) => get(`/waterSupply/gis/map/detail/${type}/${id}`)
export const getDeviceGisAllPoints = () => get('/waterSupply/device/gis/allPoints')
export const getDeviceGisAbnormalPoints = () => get('/waterSupply/device/gis/abnormalPoints')
export const getDeviceGisStatistics = () => get('/waterSupply/device/gis/statistics')

// 供水设施基础信息批量导出（后端 WaterFacilityExportController）
export const exportWaterSource = (params) => request({ url: '/api/water/sourceInfo/export', method: 'get', params, responseType: 'blob' })
export const exportWaterPlant = (params) => request({ url: '/api/water/plantInfo/export', method: 'get', params, responseType: 'blob' })
export const exportWaterPumpStation = (params) => request({ url: '/api/water/pumpStation/export', method: 'get', params, responseType: 'blob' })
export const exportWaterPipe = (params) => request({ url: '/api/water/pipe/export', method: 'get', params, responseType: 'blob' })
export const exportWaterUser = (params) => request({ url: '/api/water/userInfo/export', method: 'get', params, responseType: 'blob' })
