// SIRE API Routes

import { Router } from 'express';
import { sireRoutingService } from './sire-routing.service';
import { sireMetricsService } from './sire-metrics.service';
import { sireOptimizationService } from './sire-optimization.service';

const router = Router();

/**
 * @swagger
 * /api/v1/sire/route/calculate:
 *   post:
 *     summary: Calculate optimal route
 */
router.post('/route/calculate', async (req, res, next) => {
  try {
    const routeId = await sireRoutingService.calculateOptimalRoute(req.body);
    res.json({ routeId });
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/sire/routes/history:
 *   get:
 *     summary: Get routing history
 */
router.get('/routes/history', async (req, res, next) => {
  try {
    const { sourceBankId, destinationBankId, limit } = req.query;
    const history = await sireRoutingService.getRoutingHistory(
      sourceBankId as string,
      destinationBankId as string,
      parseInt(limit as string) || 100
    );
    res.json(history);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/sire/metrics/:bankId:
 *   get:
 *     summary: Get routing metrics
 */
router.get('/metrics/:bankId', async (req, res, next) => {
  try {
    const { limit } = req.query;
    const metrics = await sireMetricsService.getMetricsForBank(
      req.params.bankId,
      parseInt(limit as string) || 100
    );
    res.json(metrics);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/sire/route/optimize:
 *   post:
 *     summary: Optimize route
 */
router.post('/route/optimize', async (req, res, next) => {
  try {
    const { sourceBankId, destinationBankId, amount, currencyCode } = req.body;
    const routeId = await sireOptimizationService.optimizeRoute(
      sourceBankId,
      destinationBankId,
      amount,
      currencyCode
    );
    res.json({ routeId });
  } catch (error) {
      return next(error);
  }
});

export default router;

