import express from 'express';
import { authenticate } from '../middleware/authMiddleware.js';
import VocabController from '../controllers/vocabController.js';

const router = express.Router();
const vocabController = new VocabController();

router.use(authenticate);

router.get('/languages', vocabController.listLanguages);
router.get('/languages/all', vocabController.listAllLanguages);
router.post('/languages', vocabController.createLanguage);
router.post('/subscribe', vocabController.subscribe);
router.get('/languages/:languageId', vocabController.getLanguage);

// Kapitel
router.get('/languages/:languageId/chapters', vocabController.listChapters);
router.post('/languages/:languageId/chapters', vocabController.createChapter);
router.get('/languages/:languageId/vocabs', vocabController.listLanguageVocabs);
router.get('/languages/:languageId/search', vocabController.searchVocabs);

router.get('/chapters/:chapterId', vocabController.getChapter);
router.get('/chapters/:chapterId/vocabs', vocabController.listChapterVocabs);
router.post('/chapters/:chapterId/vocabs', vocabController.addVocabToChapter);

// Courses
router.post('/courses', vocabController.createCourse);
router.get('/courses', vocabController.getCourses);
router.get('/courses/my', vocabController.getMyCourses);
router.post('/courses/find-by-code', vocabController.getCourseByShareCode);
router.get('/courses/:courseId', vocabController.getCourse);
router.put('/courses/:courseId', vocabController.updateCourse);
router.delete('/courses/:courseId', vocabController.deleteCourse);

// Lessons
router.post('/courses/:courseId/lessons', vocabController.addLessonToCourse);
router.put('/lessons/:lessonId', vocabController.updateLesson);
router.delete('/lessons/:lessonId', vocabController.deleteLesson);

// Enrollment
router.post('/courses/:courseId/enroll', vocabController.enrollInCourse);
router.delete('/courses/:courseId/enroll', vocabController.unenrollFromCourse);

// Progress
router.get('/courses/:courseId/progress', vocabController.getCourseProgress);
router.get('/lessons/:lessonId', vocabController.getLesson);
router.put('/lessons/:lessonId/progress', vocabController.updateLessonProgress);

// Grammar Exercises
router.get('/grammar/exercise-types', vocabController.getExerciseTypes);
router.post('/lessons/:lessonId/grammar-exercises', vocabController.createGrammarExercise);
router.get('/lessons/:lessonId/grammar-exercises', vocabController.getGrammarExercisesForLesson);
router.get('/lessons/:lessonId/grammar-exercises/progress', vocabController.getGrammarExerciseProgress);
router.get('/grammar-exercises/:exerciseId', vocabController.getGrammarExercise);
router.post('/grammar-exercises/:exerciseId/check', vocabController.checkGrammarExerciseAnswer);
router.put('/grammar-exercises/:exerciseId', vocabController.updateGrammarExercise);
router.delete('/grammar-exercises/:exerciseId', vocabController.deleteGrammarExercise);

export default router;


