// routes/purchaseOrderRoutes.js
const express = require('express');
const router = express.Router();
const purchaseOrderController = require('../controllers/purchaseOrderController');
const { authenticate, authorize } = require('../middleware/auth'); // Your auth middleware

// All routes require authentication
router.use(authenticate);

// Purchase Order CRUD
router.get('/', authenticate,purchaseOrderController.getAllPurchaseOrders);
router.get('/:id',authenticate, purchaseOrderController.getPurchaseOrderById);
router.post('/', authenticate,authorize('admin', 'manager'), purchaseOrderController.createPurchaseOrder);
router.put('/:id',authenticate, authorize('admin', 'manager'), purchaseOrderController.updatePurchaseOrder);
router.delete('/:id',authenticate, authorize('admin', 'manager'), purchaseOrderController.deletePurchaseOrder);

// Purchase Order Actions
router.patch('/:id/approve',authenticate, authorize('admin', 'manager'), purchaseOrderController.approvePurchaseOrder);
router.patch('/:id/cancel', authenticate,authorize('admin', 'manager'), purchaseOrderController.cancelPurchaseOrder);
router.post('/:id/receive',authenticate, authorize('admin', 'manager', 'staff'), purchaseOrderController.receiveItems);

// Helper Routes
router.get('/helpers/suppliers',authenticate, purchaseOrderController.getSuppliers);
router.get('/helpers/stores', authenticate,purchaseOrderController.getStores);
router.get('/helpers/products', authenticate,purchaseOrderController.getProducts);

module.exports = router;