const express = require('express');
const { getMovementsForToday } = require('../services/lineMovementService');

const router = express.Router();

router.get('/', async (req, res) => {
  try {
    const filters = {
      player: req.query.player || null,
      stat_type: req.query.stat_type || null,
      min_movement: req.query.min_movement ? parseFloat(req.query.min_movement) : 0.5,
    };

    const movements = await getMovementsForToday('nba', filters);
    const today = new Date().toISOString().split('T')[0];

    return res.json({
      game_date: today,
      movements,
    });
  } catch (err) {
    console.error('[VYNDR] Movements error:', err.message);
    return res.status(503).json({ error: 'Movement data temporarily unavailable' });
  }
});

module.exports = router;
