import request from '@/utils/request'

// ======== 全局工作流实例监控 ========

// 查看所有租户的工作流实例列表
export function listAllInstances(params) {
  return request({ url: '/workflow/lobster/instance/list', method: 'get', params })
}

// 查看指定实例详情（跨租户）
export function getInstanceDetail(instanceId) {
  return request({ url: `/workflow/lobster/instance/${instanceId}`, method: 'get' })
}

// 查看指定实例的节点执行日志
export function getInstanceNodeLogs(instanceId) {
  return request({ url: `/workflow/lobster/instance/node-logs/${instanceId}`, method: 'get' })
}

// 强制终止指定实例（管理级操作）
export function forceTerminateInstance(instanceId, reason) {
  return request({ url: `/workflow/lobster/instance/terminate/${instanceId}`, method: 'post', params: { reason } })
}

// 全局工作流运行统计
export function getInstanceStats() {
  return request({ url: '/workflow/lobster/instance/stats', method: 'get' })
}

// ======== 全局死信队列管理 ========

export function listAllDeadLetters(params) {
  return request({ url: '/workflow/lobster/dead-letter/list', method: 'get', params })
}

export function retryAllDeadLetters() {
  return request({ url: '/workflow/lobster/dead-letter/retry-all', method: 'post' })
}

export function getDeadLetterStats() {
  return request({ url: '/workflow/lobster/dead-letter/stats', method: 'get' })
}

// ======== 全局节点审核 ========

export function listAllEventAudits(params) {
  return request({ url: '/workflow/lobster/event-audit/list', method: 'get', params })
}

export function approveEventAudit(id) {
  return request({ url: `/workflow/lobster/event-audit/approve/${id}`, method: 'post' })
}

export function rejectEventAudit(id, data) {
  return request({ url: `/workflow/lobster/event-audit/reject/${id}`, method: 'post', data })
}

export function getEventAuditDetail(id) {
  return request({ url: `/workflow/lobster/event-audit/${id}`, method: 'get' })
}

// ======== 全局优化建议 ========

export function listAllOptimization(params) {
  return request({ url: '/workflow/lobster/optimization/list', method: 'get', params })
}

export function batchAuditOptimization(data) {
  return request({ url: '/workflow/lobster/optimization/batch-audit', method: 'post', data })
}

export function getOptimizationStats() {
  return request({ url: '/workflow/lobster/optimization/stats', method: 'get' })
}

// ======== 全局Token计费统计 ========

export function listAllBillingRecords(params) {
  return request({ url: '/workflow/lobster/billing/records', method: 'get', params })
}

export function getBillingStats() {
  return request({ url: '/workflow/lobster/billing/stats', method: 'get' })
}

export function getTokenCoefficient() {
  return request({ url: '/workflow/lobster/billing/token-coefficient', method: 'get' })
}

export function updateTokenCoefficient(data) {
  return request({ url: '/workflow/lobster/billing/token-coefficient', method: 'put', data })
}