const db = require('../config/db');

const recordTest = async (req, res) => {
    try {
        const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress || 'unknown';
        
        console.log(`🔥 [Stress Test] Request received from ${ip}`);

        // Insertar en prueba_esfuerzo
        // Asume columnas 'fecha' (datetime) e 'ip' (varchar)
        const [result] = await db.query("INSERT INTO prueba_esfuerzo (fecha, ip) VALUES (NOW(), ?)", [ip]);
        
        res.json({ 
            success: true, 
            message: "Insertado en prueba_esfuerzo", 
            insertId: result.insertId,
            ip: ip 
        });
    } catch (error) {
        console.error("Stress test error:", error);
        res.status(500).json({ success: false, error: error.message });
    }
};

module.exports = { recordTest };
