const express =
  require("express");

const {
  getAdminUsers,
  createAdminUser,
  updateAdminUser,
  updateAdminUserStatus,
  resetAdminUserPassword
} = require(
  "../controllers/adminUserController"
);

const {
  verifyAdminToken
} = require(
  "../middleware/adminAuth"
);

const {
  authorizeAdminRoles
} = require(
  "../middleware/adminAuthorization"
);

const router =
  express.Router();

/* =========================================================
   AUTHENTICATION
   ========================================================= */

router.use(
  verifyAdminToken
);

/* =========================================================
   AUTHORIZATION

   Only Super Administrators can manage
   administrator accounts.
   ========================================================= */

router.use(
  authorizeAdminRoles(
    "super_admin"
  )
);

/* =========================================================
   ADMINISTRATOR USER ROUTES
   ========================================================= */

router.get(
  "/",
  getAdminUsers
);

router.post(
  "/",
  createAdminUser
);

router.patch(
  "/:adminUserId",
  updateAdminUser
);

router.patch(
  "/:adminUserId/status",
  updateAdminUserStatus
);

router.patch(
  "/:adminUserId/reset-password",
  resetAdminUserPassword
);

module.exports =
  router;