const express = require('express');
const { body } = require('express-validator');
const { 
  createOrder,
  getOrder,
  getUserOrders,
  getMerchantOrders,
  cancelOrder,
  payOrder,
  getOrderStatistics,
  getAllOrders,
  updateOrderStatus,
  deleteOrder,
  getMerchantStats
} = require('../controllers/order/index');
const { authenticateUser: authenticate, requireRole: requireAdmin, requireRole: requireMerchant } = require('../middleware/auth');

const router = express.Router();

// 创建订单
router.post('/', authenticate, createOrder);

// 获取订单详情
router.get('/:orderId', authenticate, getOrder);

// 获取订单列表
router.get('/', authenticate, getUserOrders);

// 商家获取订单列表
router.get('/merchant', authenticate, requireMerchant, getMerchantOrders);

// 取消订单
router.put('/:orderId/cancel', authenticate, cancelOrder);

// 支付订单
router.put('/:orderId/pay', authenticate, payOrder);

// 获取订单统计信息
router.get('/statistics', authenticate, getOrderStatistics);

// 管理员获取所有订单
router.get('/admin', authenticate, requireAdmin, getAllOrders);

// 管理员更新订单状态
router.put('/:orderId/status', authenticate, requireAdmin, updateOrderStatus);

// 管理员删除订单
router.delete('/:orderId', authenticate, requireAdmin, deleteOrder);

// 商家获取统计数据
router.get('/merchant/stats', authenticate, requireMerchant, getMerchantStats);

module.exports = router;