import http from '@/utils/request'

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

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

  // 创建数据订单
  createOrder (data) {
    return http.post('/dataservice/neworder', 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
    })
  },

  // 完成订单
  completeOrder (orderId, options = {}) {
    return http.post(`/dataservice/orders/${orderId}/complete`, {
      product_id: options.productId,
      dataflow_id: options.dataflowId,
      processed_by: options.processedBy || 'system'
    })
  },

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

export const api = dataOrder
