/**
 * Module Routes
 *
 * Route definitions for module endpoints
 */

import { Router } from 'express';
import { moduleController } from './module.controller';
import { authenticate } from '../../shared/middleware/auth.middleware';

const router = Router();

// All module routes require authentication except where noted
router.use(authenticate);

/**
 * @route   GET /api/modules
 * @desc    List all modules with optional filtering
 * @query   type - Filter by module type (FUNDAMENTOS, SISTEMAS_ESPACIOS, APLICACIONES)
 * @query   isPublished - Filter by published status (true/false)
 * @query   difficulty - Filter by difficulty level (BASIC, INTERMEDIATE, ADVANCED, EXPERT)
 * @query   search - Search in name and description
 * @query   page - Page number (default: 1)
 * @query   limit - Items per page (default: 50)
 * @query   sortBy - Sort field (default: order)
 * @query   sortOrder - Sort direction asc/desc (default: asc)
 * @access  Private
 */
router.get('/', moduleController.listModules.bind(moduleController));

/**
 * @route   GET /api/modules/type/:type
 * @desc    Get modules by type
 * @param   type - Module type (FUNDAMENTOS, SISTEMAS_ESPACIOS, APLICACIONES)
 * @query   page - Page number (default: 1)
 * @query   limit - Items per page (default: 50)
 * @access  Private
 */
router.get(
  '/type/:type',
  moduleController.getModulesByType.bind(moduleController)
);

/**
 * @route   GET /api/modules/:id
 * @desc    Get module by ID with optional includes
 * @param   id - Module ID
 * @query   includeExercises - Include exercises list (default: false)
 * @query   includeTopics - Include topics list (default: false)
 * @query   includeProgress - Include user progress (default: false)
 * @access  Private
 */
router.get(
  '/:id',
  moduleController.getModuleById.bind(moduleController)
);

/**
 * @route   GET /api/modules/:id/introduction
 * @desc    Get module introduction content
 * @param   id - Module ID
 * @access  Private
 */
router.get(
  '/:id/introduction',
  moduleController.getModuleIntroduction.bind(moduleController)
);

/**
 * @route   GET /api/modules/:id/examples
 * @desc    Get module examples with LaTeX formulas
 * @param   id - Module ID
 * @access  Private
 */
router.get(
  '/:id/examples',
  moduleController.getModuleExamples.bind(moduleController)
);

/**
 * @route   GET /api/modules/:id/sections
 * @desc    Get module exercise sections
 * @param   id - Module ID
 * @access  Private
 */
router.get(
  '/:id/sections',
  moduleController.getModuleExerciseSections.bind(moduleController)
);

/**
 * @route   GET /api/modules/:id/overview
 * @desc    Get module overview statistics
 * @param   id - Module ID
 * @access  Private
 */
router.get(
  '/:id/overview',
  moduleController.getModuleOverview.bind(moduleController)
);

/**
 * @route   GET /api/modules/:id/next
 * @desc    Get next module in sequence
 * @param   id - Current module ID
 * @access  Private
 */
router.get(
  '/:id/next',
  moduleController.getNextModule.bind(moduleController)
);

/**
 * @route   GET /api/modules/:id/previous
 * @desc    Get previous module in sequence
 * @param   id - Current module ID
 * @access  Private
 */
router.get(
  '/:id/previous',
  moduleController.getPreviousModule.bind(moduleController)
);

export default router;
