import express from "express";
import {
  registerUser,
  loginUser,
  logout,
  forgotPassword,
  resetPassword,
  getUserDetails,
  updatePassword,
  updateProfile,
  getSingleUser,
  getAllUser,
  getUserOrderForAdmin,
  getAllEmployee,
  deleteEmployeeById,
  updateEmployeeById,
  uploadPrincipaldistributors,
  getAllPrincipalDistributorbytmId,
  mappedbyTM,
  unmappedTMinPrincipalDistributor,
  unmappedSCinPrincipalDistributor,
  mappedbySC,
  getAllPrincipalDistributorbyscId,
  saveFCMTokenForUser,
  getAllPD,
} from "./userController.js";
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";

const router = express.Router();

router.route("/user/register").post(registerUser);

router.route("/user/login").post(loginUser);

router.route("/user/password/forgot").post(forgotPassword);

router.route("/user/password/reset/:token").put(resetPassword);

router.route("/user/logout").get(logout);

router.route("/user/details").get(isAuthenticatedUser, getUserDetails);
router
  .route("/principaldistributor/upload")
  .post(
    isAuthenticatedUser,
    authorizeRoles("admin"),
    uploadPrincipaldistributors
  );
//mapping start
router
  .route("/admin/users")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getAllUser);
  router
  .route("/admin/pd")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getAllPD);
router
  .route("/getbyTmId/:id")
  .get(
    isAuthenticatedUser,
    authorizeRoles("admin"),
    getAllPrincipalDistributorbytmId
  );
router
  .route("/getbySCId/:id")
  .get(
    isAuthenticatedUser,
    authorizeRoles("admin"),
    getAllPrincipalDistributorbyscId
  );
router.put(
  "/mappedtm/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  mappedbyTM
);
router.put(
  "/mappedSC/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  mappedbySC
);
router.patch(
  "/unmap/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  unmappedTMinPrincipalDistributor
);
router.patch(
  "/unmapSC/:id",
  isAuthenticatedUser,
  authorizeRoles("admin"),
  unmappedSCinPrincipalDistributor
);
//mapping end
router
  .route("/admin/delete-employee/:id")
  .delete(
    isAuthenticatedUser,
    authorizeRoles("admin", "Employee"),
    deleteEmployeeById
  );
router
  .route("/admin/employee")
  .get(
    isAuthenticatedUser,
    authorizeRoles("admin", "Employee"),
    getAllEmployee
  );
router
  .route("/admin/update-employee/:id")
  .put(
    isAuthenticatedUser,
    authorizeRoles("admin", "Employee"),
    updateEmployeeById
  );
router
  .route("/admin/users/orders/:id")
  .get(
    isAuthenticatedUser,
    authorizeRoles("admin", "Employee"),
    getUserOrderForAdmin
  );

router
  .route("/admin/user/:id")
  .get(isAuthenticatedUser, authorizeRoles("admin", "Employee"), getSingleUser);

router.route("/user/password/update").put(isAuthenticatedUser, updatePassword);

router.route("/user/update/profile").put(isAuthenticatedUser, updateProfile);
router.route("/user/fcm-token").post(isAuthenticatedUser, saveFCMTokenForUser);

export default router;
