const express = require('express');
const router = express.Router();
const adminWithdrawalController = require('../controllers/adminWithdrawalController');
const { authenticateAdmin } = require('../middleware/auth');
const { logAdminOperation } = require('../middleware/adminLogger');
const { requireRole } = require('../middleware/rbac');

/**
 * Admin Withdrawal Management Routes
 * Base path: /api/v1/admin/withdrawals
 * All routes require admin authentication
 */

/**
 * @route   GET /api/v1/admin/withdrawals
 * @desc    Get withdrawal list with pagination and filters
 * @access  Private (Admin)
 */
router.get(
  '/',
  authenticateAdmin,
  requireRole(['super_admin', 'admin', 'operator']),
  logAdminOperation,
  adminWithdrawalController.getWithdrawalList
);

/**
 * @route   GET /api/v1/admin/withdrawals/:id
 * @desc    Get withdrawal details
 * @access  Private (Admin)
 */
router.get(
  '/:id',
  authenticateAdmin,
  requireRole(['super_admin', 'admin', 'operator']),
  logAdminOperation,
  adminWithdrawalController.getWithdrawalDetails
);

/**
 * @route   PUT /api/v1/admin/withdrawals/:id/approve
 * @desc    Approve withdrawal request
 * @access  Private (Admin or Super Admin)
 */
router.put(
  '/:id/approve',
  authenticateAdmin,
  requireRole(['super_admin', 'admin']),
  logAdminOperation,
  adminWithdrawalController.approveWithdrawal
);

/**
 * @route   PUT /api/v1/admin/withdrawals/:id/reject
 * @desc    Reject withdrawal request
 * @access  Private (Admin or Super Admin)
 */
router.put(
  '/:id/reject',
  authenticateAdmin,
  requireRole(['super_admin', 'admin']),
  logAdminOperation,
  adminWithdrawalController.rejectWithdrawal
);

module.exports = router;
