const express = require('express');
const router = express.Router();
const { authenticate } = require('../middlewares/auth');

const materialRequestController = require('../controllers/materialRequestController');
const materialSubstitutionController = require('../controllers/materialSubstitutionController');
const materialIssueController = require('../controllers/materialIssueController');
const materialReturnNoteController = require('../controllers/materialReturnNoteController');

router.use(authenticate);

// Material Request routes
router.get('/material-request', materialRequestController.getAll);
router.get('/material-request/:id', materialRequestController.getById);
router.post('/material-request', materialRequestController.create);
router.put('/material-request/:id', materialRequestController.update);
router.delete('/material-request/:id', materialRequestController.delete);
router.post('/material-request/:id/send-to-stores', materialRequestController.sendToStores);
router.post('/material-request/:id/review', materialRequestController.review);
router.post('/material-request/:id/send-to-purchase', materialRequestController.sendToPurchase);
router.post('/material-request/:id/create-pr', materialRequestController.createPurchaseRequisition);
router.post('/material-request/:id/create-issue', materialRequestController.createMaterialIssue);

// Material Issue Note (MIN) routes (for stores to issue materials)
router.get('/material-issue-note', materialIssueController.getAll);
router.get('/material-issue-note/:id', materialIssueController.getById);
router.post('/material-issue-note', materialIssueController.create);
router.put('/material-issue-note/:id', materialIssueController.update);
router.delete('/material-issue-note/:id', materialIssueController.delete);
router.post('/material-issue-note/:id/post', materialIssueController.post);

// Material Return Note (MRN) routes
router.get('/material-return-note', materialReturnNoteController.getAll);
router.get('/material-return-note/:id', materialReturnNoteController.getById);
router.post('/material-return-note', materialReturnNoteController.create);
router.put('/material-return-note/:id', materialReturnNoteController.update);
router.delete('/material-return-note/:id', materialReturnNoteController.delete);
router.post('/material-return-note/:id/post', materialReturnNoteController.post);

// Material Substitution Routes
router.post('/substitute-item/:itemId', materialSubstitutionController.substituteMaterialRequestItem);

module.exports = router;

