const express = require('express');
const router = express.Router();
const chitGroupController = require('../controllers/chitGroupController');
const { authenticateToken, requireManager } = require('../middleware/auth');

// All routes require authentication
router.use(authenticateToken);

// Chit Group Management (Manager only)
router.post('/', requireManager, chitGroupController.createChitGroup);
router.get('/manager', requireManager, chitGroupController.getManagerChitGroups);
router.put('/:groupId', requireManager, chitGroupController.updateChitGroup);
router.delete('/:groupId', requireManager, chitGroupController.deleteChitGroup);
router.post('/:groupId/start', requireManager, chitGroupController.startChitGroup);

// Chit Group Access (Manager and Members)
router.get('/member', chitGroupController.getMemberChitGroups);
router.get('/:groupId', chitGroupController.getChitGroupDetails);
router.get('/:groupId/stats', chitGroupController.getChitGroupStats);
router.get('/:groupId/financial-data', chitGroupController.getChitGroupFinancialData);

module.exports = router;
