import express from "express";
import {
  ChangePasswordRD,
  forgotPasswordRD,
  getAllRDbypdid,
  getAllRDbyscid,
  getAllRDbytmid,
  getAllRetailDistributorApproved,
  getAllRetailDistributorwithTotalorder,
  getmyProfileRD,
  getRDId,
  loginRD,
  saveFCMTokenForRD,
  UpdateProfileRD,
  updateRDMapped,
  updateunmapRD,
  uploadRetaildistributors,
} from "./RetailDistributorController.js";
import { isAuthenticatedRD } from "../../middlewares/rdAuth.js";
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";

const router = express.Router();

router
  .route("/retaildistributor/upload")
  .post(isAuthenticatedUser, authorizeRoles("admin"), uploadRetaildistributors);
router.route("/rd-login").post(loginRD);
router.route("/rd-get-me").get(isAuthenticatedRD, getmyProfileRD);
router.post("/forgot-password", forgotPasswordRD);
router.put(
  "/rd-password/update",
  isAuthenticatedRD,

  ChangePasswordRD
);
router.patch("/rd-profile/update", isAuthenticatedRD, UpdateProfileRD);
router.post("/rd-save-fcm-token", isAuthenticatedRD, saveFCMTokenForRD);
//admin and maping
router
  .route("/getAllRD")
  .get(
    isAuthenticatedUser,
    authorizeRoles("admin"),
    getAllRetailDistributorApproved
  );
router
  .route("/getAllRDandorder")
  .get(
    isAuthenticatedUser,
    authorizeRoles("admin"),
    getAllRetailDistributorwithTotalorder
  );
router
  .route("/getRD/:id")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getRDId);
//mapping part
router
  .route("/getAllRDbytmid/:mappedTMId")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getAllRDbytmid);
router
  .route("/getAllRDbyscid/:mappedSCId")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getAllRDbyscid);
router
  .route("/getAllRDbypdid/:mappedPDId")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getAllRDbypdid);
router
  .route("/mapped/:id")
  .put(isAuthenticatedUser, authorizeRoles("admin"), updateRDMapped);
router
  .route("/unmap/:id")
  .patch(isAuthenticatedUser, authorizeRoles("admin"), updateunmapRD);
export default router;
