const router = require('express').Router();
const { authMiddleware, requirePermission } = require('../middleware/auth');
const ctrl = require('../controllers/templateController');

router.use(authMiddleware);

router.get('/courses',             ctrl.listCourseTemplates);
router.post('/courses',            requirePermission('templates.manage'), ctrl.saveCourseTemplate);
router.post('/courses/:id/create', requirePermission('templates.manage'), ctrl.createFromCourseTemplate);
router.delete('/courses/:id',      requirePermission('templates.manage'), ctrl.deleteCourseTemplate);

router.get('/lessons',             ctrl.listLessonTemplates);
router.post('/lessons',            requirePermission('templates.manage'), ctrl.saveLessonTemplate);
router.post('/lessons/:id/create', requirePermission('templates.manage'), ctrl.createFromLessonTemplate);
router.delete('/lessons/:id',      requirePermission('templates.manage'), ctrl.deleteLessonTemplate);

module.exports = router;
