import express from "express";
import { getLevels, getLevelById, getLevelForAdmin, getLevelsByTopicId, createLevel, updateLevelById, deleteLevelById, deleteLevelFileById, getPreviousLevel } from "../../controllers/contentControllers/level.js";
import { verifyLoginUser, adminOnly } from "../../middlewares/User/authUser.js";
import handleUpload from '../../middlewares/Level/uploadLevel.js';
import {checkLevelsPerTopic, autoCalculateRoutes, getSectionAndTopicByLevelId } from '../../middlewares/Level/checkLevel.js';


const router = express.Router();

router.get("/level", verifyLoginUser, getLevels);

router.get("/level/topic/:idTopic", verifyLoginUser, getLevelsByTopicId);

router.get("/level/admin", verifyLoginUser, adminOnly, getLevelForAdmin);

router.get("/level/:id", verifyLoginUser, getLevelById);

router.get("/previous/level/:next_learning", verifyLoginUser, getPreviousLevel);

router.post("/level", verifyLoginUser, adminOnly, handleUpload, checkLevelsPerTopic, autoCalculateRoutes, createLevel);

router.put("/level/:id", verifyLoginUser, adminOnly, handleUpload, getSectionAndTopicByLevelId, autoCalculateRoutes, updateLevelById);

router.delete("/level/:id", verifyLoginUser, adminOnly, getSectionAndTopicByLevelId, deleteLevelById);

router.delete("/level/file/:id", verifyLoginUser, adminOnly, deleteLevelFileById);

export default router