import express from "express";
import {
  markAttendance,
  getAttendanceByUser,
  getTodayAttendance,
  AdmingetAttendanceByUser,
} from "./AttendanceController.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 attendance for admin
router.get(
  "/attendance/today",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  getTodayAttendance
);

// Route to mark attendance for Sales Coordinators
router.post(
  "/markattendance/salescoordinator",
  isAuthenticatedSalesCoOrdinator,
  markAttendance
);

// Route to mark attendance for Territory Managers
router.post(
  "/markattendance/territorymanager",
  isAuthenticatedTerritoryManager,
  markAttendance
);

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

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

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

export default router;
