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

const router = express.Router();

/**
 * Admin Commission Routes
 */

/**
 * @route   GET /api/v1/admin/commissions
 * @desc    Get all commissions
 * @access  Private (Admin)
 */
router.get(
  '/',
  authenticateAdmin,
  requireRole(['super_admin', 'admin', 'operator']),
  adminCommissionController.getCommissions
);

/**
 * @route   GET /api/v1/admin/commissions/stats
 * @desc    Get commission statistics
 * @access  Private (Admin)
 */
router.get(
  '/stats',
  authenticateAdmin,
  requireRole(['super_admin', 'admin', 'operator']),
  adminCommissionController.getCommissionStats
);

/**
 * @route   GET /api/v1/admin/config/commission-rate
 * @desc    Get commission rate
 * @access  Private (Admin)
 */
router.get(
  '/config/commission-rate',
  authenticateAdmin,
  requireRole(['super_admin', 'admin']),
  adminCommissionController.getCommissionRate
);

/**
 * @route   PUT /api/v1/admin/config/commission-rate
 * @desc    Set commission rate
 * @access  Private (Super Admin only)
 */
router.put(
  '/config/commission-rate',
  authenticateAdmin,
  requireRole(['super_admin']),
  logAdminOperation,
  adminCommissionController.setCommissionRate
);

module.exports = router;
