import express from "express";

const router = express.Router();
import {
  Otp,
  deleteSalesCoOrdinator,
  forgotPassword,
  getAllSalesCoOrdinator,
  loginSalesCoOrdinator,
  register,
  updateMobileNumber,
  verifyUpdatedMobileOtp,
  verifyOtp,
  UpdateProfile,
  getmyProfile,
  ChangePassword,
  getOneSalesCoOrdinator,
  logout,
  getAllSalesCoOrdinatorbytmId,
  mappedbyTM,
  unmapSalesCoOrdinator,
  getAllSalesCoOrdinatorforTM_App,
  uploadSalesCoordinators,
} from "./SalesCoOrdinatorController.js";
import { isAuthenticatedSalesCoOrdinator } from "../../middlewares/SalesCoOrdinatorAuth.js";
import { isAuthenticatedTerritoryManager } from "../../middlewares/TerritoryManagerAuth.js";
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";

router.post("/register", register);
router
  .route("/upload")
  .post(isAuthenticatedUser, authorizeRoles("admin"), uploadSalesCoordinators);
router.post("/verify-otp", verifyOtp);
router.post("/login", loginSalesCoOrdinator);
router.route("/logout").get(logout);
//admin
router.get(
  "/getAll",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  getAllSalesCoOrdinator
);
router.get(
  "/getAll-TM",
  isAuthenticatedTerritoryManager,
  getAllSalesCoOrdinatorforTM_App
);
// mapping start
router.get(
  "/getbyTmId/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  getAllSalesCoOrdinatorbytmId
);
router.put(
  "/mappedtm/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  mappedbyTM
);
router.delete(
  "/unmap/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  unmapSalesCoOrdinator
);
// mapping end
router.get(
  "/getOne/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  getOneSalesCoOrdinator
);
router.get("/my-profile", isAuthenticatedSalesCoOrdinator, getmyProfile);

//Update Mobile Number
router.post(
  "/update-mobile-number/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  updateMobileNumber
);
router.post(
  "/update-mobile-number",
  isAuthenticatedSalesCoOrdinator,
  updateMobileNumber
);
router.post(
  "/verify-updated-mobile-otp",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  verifyUpdatedMobileOtp
);
router.post(
  "/verify-updated-mobile-otp",
  isAuthenticatedSalesCoOrdinator,
  verifyUpdatedMobileOtp
);
router.post("/forgot-password", forgotPassword);
router.patch(
  "/profile/update/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  UpdateProfile
);
router.patch("/profile/update", isAuthenticatedSalesCoOrdinator, UpdateProfile);
//change password
router.put(
  "/password/update/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  ChangePassword
);
router.put("/password/update", isAuthenticatedSalesCoOrdinator, ChangePassword);
//delete SalesCoOrdinator
router.delete(
  "/delete/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  deleteSalesCoOrdinator
);

router.get("/otp", Otp);

export default router;
