import express from 'express';
import { detectConvergence } from '../services/convergenceDetector.js';

const router = express.Router();

/**
 * GET /api/convergence/detect
 * Detects convergence events (3+ signals within time window)
 * Query params:
 *   - lookback: minutes to look back (default 10)
 */
router.get('/detect', async (req, res) => {
  try {
    const { lookback = 10 } = req.query; // minutes
    
    const convergences = await detectConvergence(parseInt(lookback));
    
    res.json({
      success: true,
      convergences,
      count: convergences.length,
      timestamp: new Date().toISOString()
    });
  } catch (error) {
    console.error('Convergence detection error:', error);
    res.status(500).json({ 
      success: false, 
      error: error.message,
      timestamp: new Date().toISOString()
    });
  }
});

export default router;

