const express = require("express");
const router = express.Router();
const auth = require("../middleware/authMiddleware");
const adminMiddleware = require("../middleware/adminMiddleware");
const c = require("../controllers/training-courses");

router.use(auth);

// User endpoints
router.get("/", c.getAllCourses);
router.get("/certificates", c.getMyCertificates);
router.post("/:courseId/reset-progress", c.resetCourseProgress);
router.post(
  "/:courseId/modules/:moduleId/quizzes/:quizId/check",
  c.checkQuizAnswer
);
router.get("/:courseId", c.getCourseDetail);
router.post(
  "/:courseId/modules/:moduleId/lessons/:lessonId/progress",
  c.updateLessonProgress
);
router.post("/:courseId/modules/:moduleId/complete", c.completeModule);

// Admin endpoints
router.get("/admin/courses", adminMiddleware, c.getAllCoursesAdmin);
router.post("/admin/course", adminMiddleware, c.createCourse);
router.post("/admin/course/:courseId/module", adminMiddleware, c.addModule);
router.patch("/admin/course/:courseId/module/:moduleId", adminMiddleware, c.updateModule);
router.delete("/admin/course/:courseId/module/:moduleId", adminMiddleware, c.deleteModule);
router.post(
  "/admin/course/:courseId/module/:moduleId/lesson/:lessonId/upload",
  adminMiddleware,
  c.uploadLessonVideo
);
router.delete("/admin/course/:courseId", adminMiddleware, c.deleteCourse);

module.exports = router;
