/**
 * API 统一导出
 */
export { request } from './request'
export * from './auth'
export * from './assets'
export * from './users'

/**
 * 设备类型管理 API
 */
export const getDeviceTypes = (params?: { category?: string; status?: string }) => {
  return request.get('/device-types', { params })
}

export const createDeviceType = (data: any) => {
  return request.post('/device-types', data)
}

export const updateDeviceType = (id: number, data: any) => {
  return request.put(`/device-types/${id}`, data)
}

export const deleteDeviceType = (id: number) => {
  return request.delete(`/device-types/${id}`)
}

/**
 * 角色权限 API
 */
export const getRoles = (params?: { status?: string }) => {
  return request.get('/roles', { params })
}

export const createRole = (data: any) => {
  return request.post('/roles', data)
}

export const updateRole = (id: number, data: any) => {
  return request.put(`/roles/${id}`, data)
}

export const deleteRole = (id: number) => {
  return request.delete(`/roles/${id}`)
}

export const getPermissionTree = () => {
  return request.get('/permissions/tree')
}

/**
 * 机构网点 API
 */
export const getOrganizationTree = () => {
  return request.get('/organizations/tree')
}

export const createOrganization = (data: any) => {
  return request.post('/organizations', data)
}

export const updateOrganization = (id: number, data: any) => {
  return request.put(`/organizations/${id}`, data)
}

export const deleteOrganization = (id: number) => {
  return request.delete(`/organizations/${id}`)
}

/**
 * 资产分配 API
 */
export const getAllocationOrders = (params?: any) => {
  return request.get('/allocation-orders', { params })
}

export const createAllocationOrder = (data: any) => {
  return request.post('/allocation-orders', data)
}

export const approveAllocationOrder = (id: number, data: any) => {
  return request.post(`/allocation-orders/${id}/approve`, data)
}

export const getAllocationOrderDetail = (id: number) => {
  return request.get(`/allocation-orders/${id}`)
}

/**
 * 维修管理 API
 */
export const getMaintenanceRecords = (params?: any) => {
  return request.get('/maintenance-records', { params })
}

export const createMaintenanceRecord = (data: any) => {
  return request.post('/maintenance-records', data)
}

export const updateMaintenanceRecord = (id: number, data: any) => {
  return request.put(`/maintenance-records/${id}`, data)
}

/**
 * 统计分析 API
 */
export const getStatisticsOverview = () => {
  return request.get('/statistics/overview')
}

export const getStatisticsTrend = (params: { period: string }) => {
  return request.get('/statistics/trend', { params })
}

/**
 * 调拨管理 API
 */
export const getTransferList = (params?: any) => {
  return request.get('/transfers', { params })
}

export const createTransfer = (data: any) => {
  return request.post('/transfers', data)
}

export const getTransferDetail = (id: number) => {
  return request.get(`/transfers/${id}`)
}

export const startTransfer = (id: number, data: any) => {
  return request.post(`/transfers/${id}/start`, data)
}

export const completeTransfer = (id: number) => {
  return request.post(`/transfers/${id}/complete`)
}

export const cancelTransfer = (id: number) => {
  return request.post(`/transfers/${id}/cancel`)
}

export const approveTransfer = (id: number, data: any) => {
  return request.post(`/transfers/${id}/approve`, data)
}

export const executeTransfer = (id: number) => {
  return request.post(`/transfers/${id}/execute`)
}

/**
 * 回收管理 API
 */
export const getRecoveryList = (params?: any) => {
  return request.get('/recoveries', { params })
}

export const createRecovery = (data: any) => {
  return request.post('/recoveries', data)
}

export const getRecoveryDetail = (id: number) => {
  return request.get(`/recoveries/${id}`)
}

export const startRecovery = (id: number, data: any) => {
  return request.post(`/recoveries/${id}/start`, data)
}

export const completeRecovery = (id: number) => {
  return request.post(`/recoveries/${id}/complete`)
}

export const cancelRecovery = (id: number) => {
  return request.post(`/recoveries/${id}/cancel`)
}

export const approveRecovery = (id: number, data: any) => {
  return request.post(`/recoveries/${id}/approve`, data)
}

export const executeRecovery = (id: number) => {
  return request.post(`/recoveries/${id}/execute`)
}

/**
 * 系统配置 API
 */
export const getConfigList = () => {
  return request.get('/system-config')
}

export const createConfig = (data: any) => {
  return request.post('/system-config', data)
}

export const updateConfig = (id: number, data: any) => {
  return request.put(`/system-config/${id}`, data)
}

export const deleteConfig = (id: number) => {
  return request.delete(`/system-config/${id}`)
}

export const refreshConfigCache = () => {
  return request.post('/system-config/refresh-cache')
}

/**
 * 操作日志 API
 */
export const getOperationLogs = (params?: any) => {
  return request.get('/operation-logs', { params })
}

export const getOperationLogDetail = (id: number) => {
  return request.get(`/operation-logs/${id}`)
}

/**
 * 消息通知 API
 */
export const getNotifications = (params?: any) => {
  return request.get('/notifications', { params })
}

export const getNotificationDetail = (id: number) => {
  return request.get(`/notifications/${id}`)
}

export const markAsRead = (ids: number[]) => {
  return request.put('/notifications/read', { ids })
}

export const markAsUnread = (ids: number[]) => {
  return request.post('/notifications/mark-unread', { ids })
}

export const markAllAsRead = () => {
  return request.post('/notifications/mark-all-read')
}

export const deleteNotification = (ids: number[]) => {
  return request.delete('/notifications', { data: { ids } })
}
