const express = require('express');
const router = express.Router();
const groupController = require('../controllers/groupController');

/**
 * @swagger
 * /groups:
 *   get:
 *     summary: Get all groups
 *     tags: [Groups]
 *     responses:
 *       200:
 *         description: List of groups
 */
router.get('/', groupController.getAllGroups);

/**
 * @swagger
 * /groups/{id}:
 *   get:
 *     summary: Get group by ID
 *     tags: [Groups]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *     responses:
 *       200:
 *         description: Group found
 */
router.get('/:id', groupController.getGroupById);

/**
 * @swagger
 * /groups:
 *   post:
 *     summary: Create a new group
 *     tags: [Groups]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name: { type: string }
 *     responses:
 *       201:
 *         description: Group created
 */
router.post('/', groupController.createGroup);

/**
 * @swagger
 * /groups/{id}:
 *   put:
 *     summary: Update a group
 *     tags: [Groups]
 *     parameters:
 *       - in: path
 *         name: id
 *         schema: { type: integer }
 *         required: true
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name: { type: string }
 *     responses:
 *       200:
 *         description: Group updated
 */
router.put('/:id', groupController.updateGroup);

/**
 * @swagger
 * /groups/{id}:
 *   delete:
 *     summary: Delete a group
 *     tags: [Groups]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *     responses:
 *       204:
 *         description: Deleted
 */
router.delete('/:id', groupController.deleteGroup);

/**
 * @swagger
 * /groups/{id}/users:
 *   get:
 *     summary: Get all users in a group
 *     tags: [Groups]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *     responses:
 *       200:
 *         description: Users found
 */
router.get('/:id/users', groupController.getGroupUsers);

/**
 * @swagger
 * /groups/{id}/cours:
 *   get:
 *     summary: Get all cours in a group
 *     tags: [Groups]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *     responses:
 *       200:
 *         description: Cours found
 */
router.get('/:id/cours', groupController.getGroupCours);

/**
 * @swagger
 * /groups/{id}/users:
 *   post:
 *     summary: Add a user to a group
 *     tags: [Groups]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               userId: { type: integer }
 *     responses:
 *       200:
 *         description: User added to group
 */
router.post('/:id/users', groupController.addUserToGroup);

/**
 * @swagger
 * /groups/{id}/cours:
 *   post:
 *     summary: Add a cours to a group
 *     tags: [Groups]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               courseId: { type: integer }
 *     responses:
 *       200:
 *         description: Cours added to group
 */
router.post('/:id/cours', groupController.addCoursToGroup);

/**
 * @swagger
 * /groups/{id}/users/{userId}:
 *   delete:
 *     summary: Remove a user from a group
 *     tags: [Groups]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *       - in: path
 *         name: userId
 *         required: true
 *         schema: { type: integer }
 *     responses:
 *       204:
 *         description: Removed
 */
router.delete('/:id/users/:userId', groupController.removeUserFromGroup);

/**
 * @swagger
 * /groups/{id}/cours/{courseId}:
 *   delete:
 *     summary: Remove a course from a group
 *     tags: [Groups]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *       - in: path
 *         name: courseId
 *         required: true
 *         schema: { type: integer }
 *     responses:
 *       204:
 *         description: Removed
 */
router.delete('/:id/cours/:courseId', groupController.removeCoursFromGroup);

module.exports = router;
