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

const router = express.Router();

/**
 * Admin Payment Order Routes
 */

/**
 * @route   POST /api/v1/admin/payment-orders
 * @desc    Create payment order
 * @access  Private (Admin)
 */
router.post(
  '/',
  authenticateAdmin,
  requireRole(['super_admin', 'admin', 'operator']),
  logAdminOperation,
  adminPaymentOrderController.createPaymentOrder
);

/**
 * @route   GET /api/v1/admin/payment-orders
 * @desc    Get payment orders
 * @access  Private (Admin)
 */
router.get(
  '/',
  authenticateAdmin,
  requireRole(['super_admin', 'admin', 'operator']),
  adminPaymentOrderController.getPaymentOrders
);

/**
 * @route   GET /api/v1/admin/payment-orders/:id
 * @desc    Get payment order by ID
 * @access  Private (Admin)
 */
router.get(
  '/:id',
  authenticateAdmin,
  requireRole(['super_admin', 'admin', 'operator']),
  adminPaymentOrderController.getPaymentOrderById
);

/**
 * @route   PUT /api/v1/admin/payment-orders/:id/cancel
 * @desc    Cancel payment order
 * @access  Private (Admin)
 */
router.put(
  '/:id/cancel',
  authenticateAdmin,
  requireRole(['super_admin', 'admin']),
  logAdminOperation,
  adminPaymentOrderController.cancelPaymentOrder
);

module.exports = router;
