// backend/src/routes/learningPaths.js
const express = require('express');
const router = express.Router();
const {
    getLearningPaths,
    getPathModules,
    getModuleTasks,
    enrollInPath,
    completeTask,
    getUserProgress,
    getLessonContent,
    submitAnswer,
    gradeLesson,
    getLessonProgress,
    updateLessonContent
} = require('../controllers/learningPathController');
const { protect, optionalAuth } = require('../middleware/authMiddleware');

// Public routes (can view paths without login)
router.get('/', getLearningPaths);
router.get('/:pathId/modules', optionalAuth, getPathModules);
router.get('/modules/:moduleId/tasks', optionalAuth, getModuleTasks);

// Lesson routes (require auth for subscription check)
router.get('/tasks/:taskId/lesson', protect, getLessonContent);

// Protected routes (require authentication)
router.post('/:pathId/enroll', protect, enrollInPath);
router.post('/tasks/:taskId/complete', protect, completeTask);
router.get('/user/progress', protect, getUserProgress);

// Lesson protected routes
router.post('/tasks/:taskId/questions/:questionId/answer', protect, submitAnswer);
router.post('/tasks/:taskId/grade', protect, gradeLesson);
router.get('/tasks/:taskId/progress', protect, getLessonProgress);
router.put('/tasks/:taskId/content', protect, updateLessonContent);

// Certificate route
const { getCertificate, verifyCertificate, getUserAnalytics, getMyCertificates } = require('../controllers/learningPathController');
router.get('/my-certificates', protect, getMyCertificates);
router.get('/:pathId/certificate', protect, getCertificate);
router.get('/verify/:certificateId', verifyCertificate); // Public verification

// Analytics route
router.get('/user/analytics', protect, getUserAnalytics);

module.exports = router;

