const express = require('express');
const router = express.Router();
const { MongoClient } = require('mongodb');
const uri = process.env.MONGO_URI;
const client = new MongoClient(uri);

router.get('/athletes', async (req, res) => {
  try {
    await client.connect();
    const db = client.db('swimartdb');
    const athletes = await db.collection('users')
      .find({ role: 'athlete' })
      .project({ _id: 1, name: 1 })
      .toArray();
    res.json(athletes);
  } catch (err) {
    console.error('Error al obtener atletas:', err);
    res.status(500).json({ error: 'Error interno del servidor' });
  }
});

module.exports = router;
