import { Router } from 'express';
import { OrderFulfillmentController } from '../controllers/OrderFulfillmentController';
import { requireTraceContext } from '../../core/guards/trace-context.guard';
import { requirePermission } from '../../core/guards/rbac.guard';

const router = Router();

router.post('/init-tables', requireTraceContext, requirePermission('admin'), OrderFulfillmentController.initTables);

router.post('/pull', requireTraceContext, requirePermission('order:write'), OrderFulfillmentController.pullOrder);

router.get('/', requireTraceContext, requirePermission('order:read'), OrderFulfillmentController.getOrders);

router.get('/:id', requireTraceContext, requirePermission('order:read'), OrderFulfillmentController.getOrder);

router.post('/:id/review', requireTraceContext, requirePermission('order:write'), OrderFulfillmentController.reviewOrder);

router.post('/:id/allocate', requireTraceContext, requirePermission('order:write'), OrderFulfillmentController.allocateWarehouse);

router.post('/:id/prepare-shipment', requireTraceContext, requirePermission('order:write'), OrderFulfillmentController.prepareShipment);

router.post('/:id/ship', requireTraceContext, requirePermission('order:write'), OrderFulfillmentController.shipOrder);

router.post('/:id/confirm-delivery', requireTraceContext, requirePermission('order:write'), OrderFulfillmentController.confirmDelivery);

router.post('/:id/exception', requireTraceContext, requirePermission('order:write'), OrderFulfillmentController.markAsException);

router.post('/:id/cancel', requireTraceContext, requirePermission('order:write'), OrderFulfillmentController.cancelOrder);

router.post('/batch/review', requireTraceContext, requirePermission('order:write'), OrderFulfillmentController.batchReview);

router.post('/batch/allocate', requireTraceContext, requirePermission('order:write'), OrderFulfillmentController.batchAllocate);

router.post('/batch/ship', requireTraceContext, requirePermission('order:write'), OrderFulfillmentController.batchShip);

export default router;
