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

router.get('/kpis', authenticate, requirePermission('DASHBOARD.VIEW'), dashboardController.getKPIs);
router.get('/purchase/stats', authenticate, requirePermission([
  'PURCHASE.PO.READ', 'PURCHASE.PR.READ', 'PURCHASE.GRN.READ',
  'PURCHASE.GATE_ENTRY.READ', 'PURCHASE.RFQ.READ', 'PURCHASE.VI.READ', 'PURCHASE.VQR.READ'
], { requireAll: false }), dashboardController.getPurchaseStats);

router.get('/production/stats', authenticate, requirePermission([
  'PRODUCTION.PO.*', 'PRODUCTION.MI.*', 'PRODUCTION.PC.*',
  'PRODUCTION.SR.*', 'PRODUCTION.MRP.*', 'PRODUCTION.WIP.*'
], { requireAll: false }), dashboardController.getProductionStats);

router.get('/store/stats', authenticate, requirePermission([
  'STORES.MATERIAL_REQUEST.*', 'STORES.MATERIAL_ISSUE.*', 'STORES.MATERIAL_RETURN.*',
  'INVENTORY.GR.*', 'INVENTORY.GI.*', 'INVENTORY.ST.*', 'INVENTORY.SA.*', 'INVENTORY.STOCK_REGISTER.*'
], { requireAll: false }), dashboardController.getStoreStats);

module.exports = router;

