const express = require('express');
const router = express.Router();
const CashDrawerController = require('../controllers/cashDrawerController');
const { authenticate, authorize } = require('../middleware/auth');

/**
 * All routes require authentication
 * Apply authentication middleware to all routes
 */

router.get('/reg/:registerId',CashDrawerController.getCurrentSession);



router.get(
  '/summary',
  CashDrawerController.getSummary
);

router.use(authenticate);


/**
 * @route   GET /api/cash-drawer/registers/:registerId/current
 * @desc    Get current active session for a register
 * @access  Private (Cashier, Manager, Admin)
 */


/**
 * @route   POST /api/cash-drawer/sessions
 * @desc    Open a new cash drawer session
 * @access  Private (Cashier, Manager, Admin)
 */
router.post(
  '/sessions',
  authorize(['cashier', 'manager', 'admin']),
  CashDrawerController.openSession
);

/**
 * @route   PUT /api/cash-drawer/sessions/:sessionId/close
 * @desc    Close an existing cash drawer session
 * @access  Private (Cashier, Manager, Admin)
 */
router.put(
  '/sessions/:sessionId/close',
  authorize(['cashier', 'manager', 'admin']),
  CashDrawerController.closeSession
);

/**
 * @route   POST /api/cash-drawer/activities
 * @desc    Record a cash drawer activity (cash in/out, etc.)
 * @access  Private (Cashier, Manager, Admin)
 */
router.post(
  '/activities',
  authorize(['cashier', 'manager', 'admin']),
  CashDrawerController.recordActivity
);



/**
 * @route   GET /api/cash-drawer/sessions
 * @desc    Get session history with filters
 * @access  Private (Manager, Admin)
 */
router.get(
  '/sessions',
  authorize(['manager', 'admin']),
  CashDrawerController.getSessionHistory
);

/**
 * @route   GET /api/cash-drawer/sessions/:sessionId
 * @desc    Get a specific session by ID
 * @access  Private (Manager, Admin)
 */
router.get(
  '/sessions/:sessionId',
  authorize(['manager', 'admin']),
  CashDrawerController.getSessionById
);

/**
 * @route   GET /api/cash-drawer/sessions/:sessionId/activities
 * @desc    Get all activities for a specific session
 * @access  Private (Manager, Admin)
 */
router.get(
  '/sessions/:sessionId/activities',
  authorize(['manager', 'admin']),
  CashDrawerController.getSessionActivities
);

/**
 * @route   GET /api/cash-drawer/summary
 * @desc    Get cash drawer summary/reports
 * @access  Private (Manager, Admin)
 */


module.exports = router;