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

const customerQuotationController = require('../controllers/customerQuotationController');
const customerPOController = require('../controllers/customerPOController');
const bomRequirementListPDFController = require('../controllers/bomRequirementListPDFController');

// Customer Quotation routes
router.get('/quotation', authenticate, customerQuotationController.getAll);
router.get('/quotation/material/:materialId/latest-rate', authenticate, customerQuotationController.getLatestRateByMaterial);
router.get('/quotation/:id/pdf', authenticate, customerQuotationController.generatePDF);
router.put('/quotation/:id/submit', authenticate, customerQuotationController.submit);
router.put('/quotation/:id/approve', authenticate, customerQuotationController.approve);
router.get('/quotation/:id', authenticate, customerQuotationController.getById);
router.post('/quotation', authenticate, customerQuotationController.create);
router.put('/quotation/:id', authenticate, customerQuotationController.update);
router.delete('/quotation/:id', authenticate, customerQuotationController.delete);

// Customer PO routes
router.get('/po', authenticate, customerPOController.getAll);
router.post('/po', authenticate, customerPOController.create);
// Specific routes before generic :id routes
router.post('/po/bom-list-pdf', authenticate, customerPOController.generateBOMListPDF);
router.post('/po/bom-list-simple-pdf', authenticate, customerPOController.generateBOMListSimplePDF);
router.post('/po/bom-list', authenticate, customerPOController.getBOMList);
router.post('/po/bom-requirement-list-pdf', authenticate, bomRequirementListPDFController.generateBOMRequirementListPDF);
router.post('/po/raw-materials-requirements-pdf', authenticate, customerPOController.generateRawMaterialsRequirementsPDF);
// Routes with :id parameter - specific routes first
router.put('/po/:id/submit', authenticate, customerPOController.submit);
router.put('/po/:id/approve', authenticate, customerPOController.approve);
router.put('/po/:id/release', authenticate, customerPOController.release);
router.post('/po/:id/convert-to-production-orders', authenticate, customerPOController.convertToProductionOrders);
router.post('/po/:id/convert-items-to-production-orders', authenticate, customerPOController.convertItemsToProductionOrders);
// Get all released PO items
router.get('/po/released-items', authenticate, customerPOController.getReleasedPOItems);
// Generic :id routes last (specific /po/:id/... before /po/:id)
router.get('/po/:id/process-flow', authenticate, customerPOController.getProcessFlow);
router.get('/po/:id', authenticate, customerPOController.getById);
router.put('/po/:id', authenticate, customerPOController.update);
router.delete('/po/:id', authenticate, customerPOController.delete);

module.exports = router;

