const router = require('express').Router();
const ctrl = require('../controllers/session.controller');
const { authenticate, authorize } = require('../middlewares/auth');
const { validate } = require('../middlewares/validate');
const { timesheetSchemas, sessionSchemas } = require('../validators');

router.use(authenticate);

// Any authenticated user can end their own session
router.post('/end', validate({ body: timesheetSchemas.empty }), ctrl.endSession);

// Admin only: force end a specific session
router.post(
	'/force-end',
	authorize('admin'),
	validate({ body: sessionSchemas.forceEnd }),
	ctrl.forceEndSession
);

// Admin only: view session data
router.get('/active', authorize('admin'), ctrl.getActiveSessions);
router.get('/history', authorize('admin'), ctrl.getSessionHistory);
router.get('/attendance', authorize('admin'), ctrl.getAttendanceReport);

module.exports = router;
