const mysql = require('mysql2/promise');
const path = require('path');
// KOSORA HANO: Kugira ngo isome .env iri hanze neza kabone n'ubwo yaba iri muri src
require('dotenv').config({ path: path.resolve(__dirname, '../../.env') });

const db = mysql.createPool({
    host: process.env.DB_HOST,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_NAME,
    waitForConnections: true,
    connectionLimit: 10,
    queueLimit: 0
});

db.getConnection()
    .then(() => console.log('🚀 MySQL Database Connected Safely!'))
    .catch((err) => console.error('❌ Database connection failed:', err));

module.exports = db;
