import express from "express";

const router = express.Router();
import {
  Otp,
  deleteTerritoryManager,
  forgotPassword,
  getAllTerritoryManager,
  loginTerritoryManager,
  register,
  updateMobileNumber,
  verifyUpdatedMobileOtp,
  verifyOtp,
  UpdateProfile,
  getmyProfile,
  ChangePassword,
  getOneTerritoryManager,
  logout,
  uploadTerritoryManagers,
} from "./TerritoryManagerController.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"), uploadTerritoryManagers);
router.post("/verify-otp", verifyOtp);
router.post("/login", loginTerritoryManager);
router.route("/logout").get(logout);
//admin
router.get(
  "/getAll",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  getAllTerritoryManager
);
router.get(
  "/getOne/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  getOneTerritoryManager
);
router.get("/my-profile", isAuthenticatedTerritoryManager, getmyProfile);

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

router.put("/password/update", isAuthenticatedTerritoryManager, ChangePassword);
//delete TerritoryManager
router.delete(
  "/delete/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  deleteTerritoryManager
);

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

export default router;
