import express from "express";
import { getLevels, getLevelById, getLevelForAdmin, getLevelsByTopicId, createLevel, updateLevelById, deleteLevelById, deleteLevelFilesById, getPreviousLevel, uploadLevelFile, getLevelFiles } from "../../controllers/contentControllers/level.js";
import { verifyLoginUser, adminOnly } from "../../middlewares/User/authUser.js";
import handleUpload from '../../middlewares/Level/uploadLevel.js';
import handleUploadFile from "../../middlewares/Level/uploadLevelFile.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.get("/level/file/:levelId", verifyLoginUser, getLevelFiles);

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

router.post("/level/file/:levelId", verifyLoginUser, adminOnly, handleUploadFile, uploadLevelFile);

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);

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

export default router