import api from './request'

// 订单相关API
export const getOrders = (params) => {
  return api.get('/orders', { params })
}

export const getOrderById = (id) => {
  return api.get(`/orders/${id}`)
}

export const createOrder = (orderData) => {
  return api.post('/orders/create', orderData)
}

export const updateOrderStatus = (id, status, notes) => {
  return api.post(`/orders/${id}/status`, {
    status,
    notes
  })
}

export const cancelOrder = (id, reason) => {
  return api.post(`/orders/${id}/cancel`, {
    reason
  })
}

export const shipOrder = (id, trackingNumber) => {
  return api.post(`/orders/${id}/ship`, {
    trackingNumber
  })
}

export const completeOrder = (id) => {
  return api.post(`/orders/${id}/complete`)
}

export const createOrderPayment = (id, paymentMethod) => {
  return api.post(`/orders/${id}/pay`, {
    paymentMethod
  })
}

// 管理员订单API（使用普通订单接口，后端会根据用户角色返回相应数据）
export const getAdminOrders = (params) => {
  return api.get('/orders', { params })
}

// 订单统计API
export const getOrderStats = () => {
  return api.get('/orders/stats')
}

// 批量删除订单
export const deleteOrders = (orderIds) => {
  return api.delete('/orders/batch', { data: orderIds })
}

// 删除单个订单
export const deleteOrder = (id) => {
  return api.delete(`/orders/${id}`)
}