import request from '@/utils/request'

// ============ 接报管理 ============
export function getEventReportPage(pageNum, pageSize, params) {
  return request({ url: '/api/dispatch/report/findByPage', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function getEventReportById(id) {
  return request({ url: '/api/dispatch/report/getById/' + id, method: 'get' })
}
export function addEventReport(data) {
  return request({ url: '/api/dispatch/report/save', method: 'post', data })
}
export function updateEventReport(data) {
  return request({ url: '/api/dispatch/report/updateById', method: 'put', data })
}
export function deleteEventReport(id) {
  return request({ url: '/api/dispatch/report/deleteById', method: 'delete', params: { id } })
}
export function acceptEventReport(id) {
  return request({ url: '/api/dispatch/report/accept/' + id, method: 'put' })
}
export function rejectEventReport(id, remark) {
  return request({ url: '/api/dispatch/report/reject/' + id, method: 'put', params: { remark } })
}

// ============ 初判核实 ============
export function getEventVerifyPage(pageNum, pageSize, params) {
  return request({ url: '/api/dispatch/verify/findByPage', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function getEventVerifyById(id) {
  return request({ url: '/api/dispatch/verify/getById/' + id, method: 'get' })
}
export function addEventVerify(data) {
  return request({ url: '/api/dispatch/verify/save', method: 'post', data })
}
export function updateEventVerify(data) {
  return request({ url: '/api/dispatch/verify/updateById', method: 'put', data })
}
export function deleteEventVerify(id) {
  return request({ url: '/api/dispatch/verify/deleteById', method: 'delete', params: { id } })
}
export function verifyEvent(data) {
  return request({ url: '/api/dispatch/verify/verify', method: 'put', data })
}

// ============ 转接报送 ============
export function getEventTransferPage(pageNum, pageSize, params) {
  return request({ url: '/api/dispatch/transfer/findByPage', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function getEventTransferById(id) {
  return request({ url: '/api/dispatch/transfer/getById/' + id, method: 'get' })
}
export function addEventTransfer(data) {
  return request({ url: '/api/dispatch/transfer/save', method: 'post', data })
}
export function updateEventTransfer(data) {
  return request({ url: '/api/dispatch/transfer/updateById', method: 'put', data })
}
export function deleteEventTransfer(id) {
  return request({ url: '/api/dispatch/transfer/deleteById', method: 'delete', params: { id } })
}
export function doTransfer(data) {
  return request({ url: '/api/dispatch/transfer/doTransfer', method: 'put', data })
}
export function doEventReport(data) {
  return request({ url: '/api/dispatch/transfer/doReport', method: 'put', data })
}
export function getTransferLogs(transferId) {
  return request({ url: '/api/dispatch/transfer/getTransferLogs/' + transferId, method: 'get' })
}

// ============ 工作催办 ============
export function getEventUrgePage(pageNum, pageSize, params) {
  return request({ url: '/api/dispatch/urge/findByPage', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function getEventUrgeById(id) {
  return request({ url: '/api/dispatch/urge/getById/' + id, method: 'get' })
}
export function addEventUrge(data) {
  return request({ url: '/api/dispatch/urge/save', method: 'post', data })
}
export function updateEventUrge(data) {
  return request({ url: '/api/dispatch/urge/updateById', method: 'put', data })
}
export function deleteEventUrge(id) {
  return request({ url: '/api/dispatch/urge/deleteById', method: 'delete', params: { id } })
}
export function doUrge(data) {
  return request({ url: '/api/dispatch/urge/doUrge', method: 'post', data })
}
export function closeUrge(id) {
  return request({ url: '/api/dispatch/urge/closeUrge/' + id, method: 'put' })
}
export function getUrgeDetails(urgeId) {
  return request({ url: '/api/dispatch/urge/getUrgeDetails/' + urgeId, method: 'get' })
}

// ============ 跟踪解除 ============
export function getEventTrackPage(pageNum, pageSize, params) {
  return request({ url: '/api/dispatch/track/findByPage', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function getEventTrackById(id) {
  return request({ url: '/api/dispatch/track/getById/' + id, method: 'get' })
}
export function addEventTrack(data) {
  return request({ url: '/api/dispatch/track/save', method: 'post', data })
}
export function updateEventTrack(data) {
  return request({ url: '/api/dispatch/track/updateById', method: 'put', data })
}
export function deleteEventTrack(id) {
  return request({ url: '/api/dispatch/track/deleteById', method: 'delete', params: { id } })
}
export function addTrackLog(data) {
  return request({ url: '/api/dispatch/track/addTrackLog', method: 'post', data })
}
export function releaseEvent(id) {
  return request({ url: '/api/dispatch/track/release/' + id, method: 'put' })
}
export function closeEvent(id) {
  return request({ url: '/api/dispatch/track/close/' + id, method: 'put' })
}
export function getTrackLogs(trackId) {
  return request({ url: '/api/dispatch/track/getTrackLogs/' + trackId, method: 'get' })
}

// ============ 应急事件分级 ============
export function getEventGradePage(pageNum, pageSize, params) {
  return request({ url: '/api/dispatch/grade/findByPage', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function addEventGrade(data) {
  return request({ url: '/api/dispatch/grade/save', method: 'post', data })
}
export function updateEventGrade(data) {
  return request({ url: '/api/dispatch/grade/updateById', method: 'put', data })
}
export function deleteEventGrade(id) {
  return request({ url: '/api/dispatch/grade/deleteById', method: 'delete', params: { id } })
}
export function getGradesByCategory(category) {
  return request({ url: '/api/dispatch/grade/listByCategory', method: 'get', params: { category } })
}

// ============ 应急预案分类 ============
export function getPlanCategoryTree() {
  return request({ url: '/api/dispatch/plan-category/getCategoryTree', method: 'get' })
}
export function addPlanCategory(data) {
  return request({ url: '/api/dispatch/plan-category/save', method: 'post', data })
}
export function updatePlanCategory(data) {
  return request({ url: '/api/dispatch/plan-category/updateById', method: 'put', data })
}
export function deletePlanCategory(id) {
  return request({ url: '/api/dispatch/plan-category/deleteById', method: 'delete', params: { id } })
}

// ============ 应急预案 ============
export function getEventPlanPage(pageNum, pageSize, params) {
  return request({ url: '/api/dispatch/plan/findByPage', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function getEventPlanById(id) {
  return request({ url: '/api/dispatch/plan/getById/' + id, method: 'get' })
}
export function addEventPlan(data) {
  return request({ url: '/api/dispatch/plan/save', method: 'post', data })
}
export function updateEventPlan(data) {
  return request({ url: '/api/dispatch/plan/updateById', method: 'put', data })
}
export function deleteEventPlan(id) {
  return request({ url: '/api/dispatch/plan/deleteById', method: 'delete', params: { id } })
}

// ============ 应急事件数据查询与统计 ============
export function getEventRecordPage(pageNum, pageSize, params) {
  return request({ url: '/api/dispatch/event-record/findByPage', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function getEventRecordStats(params) {
  return request({ url: '/api/dispatch/event-record/stats', method: 'get', params })
}
export function getEventRecordById(id) {
  return request({ url: '/api/dispatch/event-record/getById/' + id, method: 'get' })
}
export function addEventRecord(data) {
  return request({ url: '/api/dispatch/event-record/save', method: 'post', data })
}
export function updateEventRecord(data) {
  return request({ url: '/api/dispatch/event-record/updateById', method: 'put', data })
}
export function deleteEventRecord(id) {
  return request({ url: '/api/dispatch/event-record/deleteById', method: 'delete', params: { id } })
}

// ============ 数字预案库匹配（应急预案选择） ============
export function getPlanLibraryList() {
  return request({ url: '/api/dispatch/plan-library/list', method: 'get' })
}
export function matchPlan(data) {
  return request({ url: '/api/dispatch/plan-library/match', method: 'post', data })
}
export function matchPlanByTopic(data) {
  return request({ url: '/api/dispatch/plan-library/matchByTopic', method: 'post', data })
}
export function getPlanMatchHistory(limit = 10) {
  return request({ url: '/api/dispatch/plan-library/history', method: 'get', params: { limit } })
}
export function applyPlan(data) {
  return request({ url: '/api/dispatch/plan-library/apply', method: 'post', data })
}

// ============ 应急预案审批 ============
export function getPlanApprovalPage(pageNum, pageSize, params) {
  return request({ url: '/api/dispatch/plan-approval/findByPage', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function getPlanApprovalById(id) {
  return request({ url: '/api/dispatch/plan-approval/getById/' + id, method: 'get' })
}
export function submitPlanForApproval(id) {
  return request({ url: '/api/dispatch/plan-approval/submitForApproval/' + id, method: 'put' })
}
export function createPlanApproval(planId) {
  return request({ url: '/api/dispatch/plan-approval/submit/' + planId, method: 'post' })
}
export function approvePlan(id) {
  return request({ url: '/api/dispatch/plan-approval/approve/' + id, method: 'put' })
}
export function rejectPlan(id) {
  return request({ url: '/api/dispatch/plan-approval/reject/' + id, method: 'put' })
}
export function publishPlan(id) {
  return request({ url: '/api/dispatch/plan-approval/publish/' + id, method: 'put' })
}
export function getApprovalSteps(approvalId) {
  return request({ url: '/api/dispatch/plan-approval-step/listByApprovalId', method: 'get', params: { approvalId } })
}

// ============ 应急事件统一档案（全生命周期闭环） ============
// 接报 -> 受理 -> 核实 -> 转接/报送 -> 跟踪/催办 -> 解除 -> 关闭
export function getEventPage(pageNum, pageSize, params) {
  return request({ url: '/api/dispatch/event/findByPage', method: 'get', params: { pageNum, pageSize, ...params } })
}
export function getEventDetail(id) {
  return request({ url: '/api/dispatch/event/getDetail/' + id, method: 'get' })
}
export function getEventStats(params) {
  return request({ url: '/api/dispatch/event/stats', method: 'get', params })
}
export function saveEventReport(data) {
  return request({ url: '/api/dispatch/event/saveReport', method: 'post', data })
}
export function acceptEvent(id) {
  return request({ url: '/api/dispatch/event/accept', method: 'post', data: { id } })
}
export function verifyEventInfo(data) {
  return request({ url: '/api/dispatch/event/verify', method: 'post', data })
}
export function transferEvent(data) {
  return request({ url: '/api/dispatch/event/transfer', method: 'post', data })
}
export function reportEvent(data) {
  return request({ url: '/api/dispatch/event/report', method: 'post', data })
}
export function trackEvent(data) {
  return request({ url: '/api/dispatch/event/track', method: 'post', data })
}
export function releaseEventInfo(id) {
  return request({ url: '/api/dispatch/event/release', method: 'post', data: { id } })
}
export function closeEventInfo(data) {
  return request({ url: '/api/dispatch/event/close', method: 'post', data })
}
export function updateEventInfo(data) {
  return request({ url: '/api/dispatch/event/updateById', method: 'put', data })
}
export function deleteEventInfo(id) {
  return request({ url: '/api/dispatch/event/deleteById', method: 'delete', params: { id } })
}

// ============ 应急事件事后评估（总结评估） ============
// 事件（已解除/已关闭） -> 四维评分 -> 生成报告/录入案例库
// 查询单事件评估（无则返回 null）
export function getEventAssess(eventId) {
  return request({ url: '/api/dispatch/assess/findByEventId', method: 'get', params: { eventId } })
}
// 批量查询评估（列表标记已评估/待评估）
export function listEventAssess(eventIds) {
  return request({ url: '/api/dispatch/assess/listByEventIds', method: 'get', params: { eventIds: eventIds.join(',') } })
}
// 保存/更新评估（自动计算综合分与等级；仅传 eventId+caseFlag 表示录入案例库）
export function saveEventAssess(data) {
  return request({ url: '/api/dispatch/assess/save', method: 'post', data })
}
// 删除评估（重新评估）
export function deleteEventAssess(eventId) {
  return request({ url: '/api/dispatch/assess/delete', method: 'delete', params: { eventId } })
}
