const router = require("express").Router();
const { authenticateAdmin, audit } = require("../../middleware");
const { authLimiter, passwordResetLimiter, verificationLimiter } = require('../../middleware/rateLimiter');
const { rules, body, validate } = require("../../middleware/validation");

// ✅ NEW
const AdminUserPlansController = require("../../controllers/admin/userPlansController");


// list user plans (with plan details)
router.get(
  "/",
  authenticateAdmin,
  AdminUserPlansController.listPlans
);

router.get(
  "/:userId/user-plans",
  authenticateAdmin,
  AdminUserPlansController.listUserPlans
);

// create user plan (admin purchase on behalf)
router.post(
  "/:userId/user-plans",
  authenticateAdmin,
  audit("user_plans.create", "user_plan"),
  AdminUserPlansController.createUserPlan
);

// update (light edit: endDate/status/metadata etc)
router.patch(
  "/:userId/user-plans/:userPlanId",
  authenticateAdmin,
  audit("user_plans.update", "user_plan"),
  AdminUserPlansController.updateUserPlan
);

// pause
router.post(
  "/:userId/user-plans/:userPlanId/pause",
  authenticateAdmin,
  audit("user_plans.pause", "user_plan"),
  AdminUserPlansController.pauseUserPlan
);

// resume
router.post(
  "/:userId/user-plans/:userPlanId/resume",
  authenticateAdmin,
  audit("user_plans.resume", "user_plan"),
  AdminUserPlansController.resumeUserPlan
);

// stop (end)
router.post(
  "/:userId/user-plans/:userPlanId/stop",
  authenticateAdmin,
  audit("user_plans.stop", "user_plan"),
  AdminUserPlansController.stopUserPlan
);

// add ROI transaction for a plan
router.post(
  "/:userId/user-plans/:userPlanId/roi",
  authenticateAdmin,
  audit("user_plans.roi", "transaction"),
  AdminUserPlansController.addRoiToUserPlan
);

// Withdrawals (separate) - left as is in your file
module.exports = router;