require('dotenv').config();
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 3000;

// Middlewares
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}))
app.use(express.static(path.join(__dirname, 'public')));


// Rutas
const userRoutes = require('./routes/userRoutes');
const animeRoutes = require('./routes/animeRoutes');
const mangaRoutes = require('./routes/mangaRoutes');
const anilistRoutes = require('./routes/anilistRoutes');
const activityRoutes = require('./routes/activityRoutes');

// Prefijos de rutas
app.use('/users', userRoutes);
app.use('/anime', animeRoutes);
app.use('/manga', mangaRoutes);
app.use('/anilist', anilistRoutes);
app.use('/api/activity', activityRoutes);

// Ruta raíz de prueba
app.get('/', (req, res) => {
    res.send('🎉 API de YomiTrack funcionando correctamente');
});

// Inicio del servidor
app.listen(PORT, () => {
    console.log(`🚀 Servidor backend corriendo en http://localhost:${PORT}`);
});
