// routes/mpesaRoutes.js
const express = require('express');
const {
  initiatePayment,
  handleCallback,
  queryPaymentStatus,
  getPaymentByOrderId,
} = require('../controllers/mpesaController');

const router = express.Router();

/**
 * @route   POST /api/mpesa/pay
 * @desc    Initiate M-Pesa STK push
 * @access  Private (requires authentication in production)
 * @body    { phoneNumber, amount, orderId, transactionDesc }
 */
router.post('/pay', initiatePayment);

/**
 * @route   POST /api/mpesa/callback
 * @desc    Handle M-Pesa callback from Safaricom
 * @access  Public (M-Pesa service)
 */
router.post('/callback', handleCallback);

/**
 * @route   GET /api/mpesa/status/:checkoutRequestID
 * @desc    Query payment status
 * @access  Private (requires authentication in production)
 */
router.get('/status/:checkoutRequestID', queryPaymentStatus);

/**
 * @route   GET /api/mpesa/payment/:orderId
 * @desc    Get payment by order ID
 * @access  Private (requires authentication in production)
 */
router.get('/payment/:orderId', getPaymentByOrderId);

module.exports = router;