const express = require('express');
const {
  getAllProducts,
  getProduct,
  createProduct,
  updateProduct,
  deleteProduct,
  updateProductStatus,
  updateInventory,
  getProductStats,
  getCategories,
  getBrands,
  bulkUpdateProducts,
  getLowStockProducts
} = require('../controllers/productController');
const { protect } = require('../middleware/auth');
const { checkModulePermission } = require('../middleware/checkPermission');

const router = express.Router();

router.use(protect);

router.get('/stats', checkModulePermission('products', 'read'), getProductStats);
router.get('/categories', checkModulePermission('products', 'read'), getCategories);
router.get('/brands', checkModulePermission('products', 'read'), getBrands);
router.get('/low-stock', checkModulePermission('products', 'read'), getLowStockProducts);
router.get('/', checkModulePermission('products', 'read'), getAllProducts);
router.get('/:id', checkModulePermission('products', 'read'), getProduct);
router.post('/', checkModulePermission('products', 'create'), createProduct);
router.post('/bulk-update', checkModulePermission('products', 'edit'), bulkUpdateProducts);
router.patch('/:id/status', checkModulePermission('products', 'edit'), updateProductStatus);
router.patch('/:id/inventory', checkModulePermission('products', 'edit'), updateInventory);
router.patch('/:id', checkModulePermission('products', 'edit'), updateProduct);
router.delete('/:id', checkModulePermission('products', 'delete'), deleteProduct);

module.exports = router;