// routes/sales.js
const express = require('express');
const router = express.Router();
const salesController = require('../controllers/salesController');
const transactionController = require('../controllers/transactionController');

const productController = require('../controllers/productController');
const { authenticate, authorize, verifyStoreAccess, verifyStoreAccessOrAdmin } = require('../middleware/auth');

// Public routes (or routes that don't require specific roles)

router.get('/recent', transactionController.getRecentTransactions);

router.get('/stats', salesController.getStats);
//router.get('/recent', salesController.getRecentSales);
router.get('/:id', salesController.getSaleById);



router.get('/payment-stats', transactionController.getPaymentStatistics);
// router.get('/products/top', productController.getTopProducts);

// Protected routes
router.use(authenticate);
router.get('/', salesController.getAllSales);
router.post('/', authorize(['admin', 'manager', 'cashier']), salesController.createSale);
router.put('/:id', authorize(['admin', 'manager']), salesController.updateSale);
router.delete('/:id', authorize(['admin']), salesController.deleteSale);

module.exports = router;