import { Router, Request, Response } from 'express';
import { cacheMiddleware } from '../middleware/cache';
import { getArbitrageOpportunities } from '../../services/arbitrage-scanner';

const router = Router();

/**
 * GET /api/v1/arbitrage/opportunities
 * Returns list of triangular arbitrage cycles with expected PnL, risk score, capital required.
 * Spec: repo_ready_graphviz_and_liquidity_heatmap_spec.md §2.4.4
 */
router.get(
  '/arbitrage/opportunities',
  cacheMiddleware(30 * 1000),
  async (req: Request, res: Response) => {
    try {
      const opportunities = await getArbitrageOpportunities();
      res.json({ opportunities });
    } catch (error) {
      // eslint-disable-next-line no-console -- route error logging
      console.error('Arbitrage opportunities error:', error);
      res.status(500).json({ error: 'Internal server error' });
    }
  }
);

export default router;
