/**
 * Department Routes
 */

const express = require("express");
const router = express.Router();
const { body } = require("express-validator");
const { validate } = require("../middleware/validationMiddleware");
const { authenticate, authorize } = require("../middleware/authMiddleware");
const departmentController = require("../controllers/departmentController");

// Validation rules
const createDepartmentValidation = [
  body("name").notEmpty().withMessage("Department name is required"),
];

// Apply authentication to all routes
router.use(authenticate);

// Routes
router.get("/", departmentController.getAllDepartments);
router.get("/:id", departmentController.getDepartmentById);
router.get("/:id/employees", departmentController.getDepartmentWithEmployees);
router.post(
  "/",
  authorize("Admin"),
  createDepartmentValidation,
  validate,
  departmentController.createDepartment,
);
router.put("/:id", authorize("Admin"), departmentController.updateDepartment);
router.delete(
  "/:id",
  authorize("Admin"),
  departmentController.deleteDepartment,
);

module.exports = router;
