const { Router } = require("express");
const {
  createDemo,
  getAllDemos,
  getPublicDemos,
  getTeacherDemos,
  endDemo, // <-- imported
} = require("../controllers/demo.controller");

const { authMiddleware } = require("../middlewares/auth.middleware");
const { authorizeRoles } = require("../middlewares/role.middleware");

const demoRouter = Router();

/* =======================
   Admin Routes
======================= */
demoRouter.post(
  "/",
  authMiddleware,
  authorizeRoles("admin"),
  createDemo
);

demoRouter.get(
  "/",
  authMiddleware,
  authorizeRoles("admin"),
  getAllDemos
);

// End demo
demoRouter.patch(
  "/end/:id",
  authMiddleware,
  authorizeRoles("admin"),
  endDemo
);

/* =======================
   Public Routes
======================= */
demoRouter.get("/public", getPublicDemos);

/* =======================
   Teacher Routes
======================= */
demoRouter.get(
  "/teacher",
  authMiddleware,
  authorizeRoles("teacher"),
  getTeacherDemos
);

module.exports = demoRouter;
