"use strict";

const router = require("express").Router();
const { authenticateAdmin, audit } = require("../../middleware");
const AdminUsersController = require("../../controllers/admin/usersController");

// List + Search + Filters + Pagination
router.get("/", authenticateAdmin, AdminUsersController.getUsers);

// Create user (auto-generates temp password/pin if not provided)
router.post("/", authenticateAdmin, audit("users.create", "user"), AdminUsersController.createUser);

// Read
router.get("/:userId", authenticateAdmin, AdminUsersController.getUserById);

// Update
router.patch("/:userId", authenticateAdmin, audit("users.update", "user"), AdminUsersController.updateUser);

// Delete
router.delete("/:userId", authenticateAdmin, audit("users.delete", "user"), AdminUsersController.deleteUser);

// Status actions
router.post("/:userId/suspend", authenticateAdmin, audit("users.suspend", "user"), AdminUsersController.suspendUser);
router.post("/:userId/hold", authenticateAdmin, audit("users.hold", "user"), AdminUsersController.holdUser);
router.post("/:userId/disable", authenticateAdmin, audit("users.disable", "user"), AdminUsersController.disableUser);
router.post("/:userId/activate", authenticateAdmin, audit("users.activate", "user"), AdminUsersController.unsuspendUser);

// Balance topup
router.post("/:userId/update-bal", authenticateAdmin, audit("users.update_balance", "user"), AdminUsersController.updateBalance);
router.post("/:userId/billing", authenticateAdmin, audit("users.update_billing", "user"), AdminUsersController.updateBilling);

// ✅ Notify (in-app notification)
router.post("/:userId/notify", authenticateAdmin, audit("users.notify", "notification"), AdminUsersController.notifyUser);

module.exports = router;