import http from '@/utils/request'

const dataOrder = {
  // 获取数据订单列表
  getOrders (params) {
    return http.get('/dataservice/orderlist', params)
  },

  // 获取数据订单详情
  getOrderDetail (orderId) {
    return http.get(`/dataservice/orders/${orderId}/detail`)
  },

  // 创建数据订单
  createOrder (data) {
    return http.post('/dataservice/neworder', data)
  },

  // 更新数据订单
  updateOrder (orderId, data) {
    return http.put(`/dataservice/orders/${orderId}/update`, data)
  },

  // 分析数据订单
  analyzeOrder (orderId) {
    return http.post(`/dataservice/orders/${orderId}/analyze`)
  },

  // 审批通过订单
  approveOrder (orderId, processedBy = 'admin') {
    return http.post(`/dataservice/orders/${orderId}/approve`, {
      processed_by: processedBy
    })
  },

  // 驳回订单
  rejectOrder (orderId, reason, processedBy = 'admin') {
    return http.post(`/dataservice/orders/${orderId}/reject`, {
      reason,
      processed_by: processedBy
    })
  },

  // 设置数据产品就绪状态 - n8n工作流自动调用
  // setOrderOnboard (orderId, options = {}) {
  //   return http.post(`/dataservice/orders/${orderId}/onboard`, {
  //     product_id: options.productId,
  //     dataflow_id: options.dataflowId,
  //     processed_by: options.processedBy || 'n8n-workflow'
  //   })
  // },

  // 完成订单
  completeOrder (orderId, processedBy = 'user') {
    return http.post(`/dataservice/orders/${orderId}/complete`, {
      processed_by: processedBy
    })
  },

  // 删除订单
  deleteOrder (orderId) {
    return http.put(`/dataservice/orders/${orderId}/delete`)
  }
}

export const api = dataOrder
