import express from "express";
import {
  markLeave,
  getLeaveByUser,
  getTodayLeave,
  AdmingetLeaveByUser,
} from "./LeaveController.js";
import { isAuthenticatedSalesCoOrdinator } from "../../middlewares/SalesCoOrdinatorAuth.js";
import { isAuthenticatedTerritoryManager } from "../../middlewares/TerritoryManagerAuth.js";
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";

const router = express.Router();

// Place more specific routes first

// Route to get today's leave for admin
router.get(
  "/leave/today",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  getTodayLeave
);

// Route to mark leave for Sales Coordinators
router.post(
  "/markleave/salescoordinator",
  isAuthenticatedSalesCoOrdinator,
  markLeave
);

// Route to mark leave for Territory Managers
router.post(
  "/markleave/territorymanager",
  isAuthenticatedTerritoryManager,
  markLeave
);

// Route to get leave for the logged-in sales coordinator
router.get(
  "/leave/salescoordinator",
  isAuthenticatedSalesCoOrdinator,
  getLeaveByUser
);

// Route to get leave for the logged-in territory manager
router.get(
  "/leave/territorymanager",
  isAuthenticatedTerritoryManager,
  getLeaveByUser
);

// Admin route to get leave by user ID
router.get(
  "/leave/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  AdmingetLeaveByUser
);

export default router;
