import mysql from "mysql2/promise";

let pool: mysql.Pool | null = null;

export function getPool(): mysql.Pool {
  if (!pool) {
    pool = mysql.createPool({
      host: process.env.MYSQL_HOST || "185.208.181.153",
      port: Number(process.env.MYSQL_PORT) || 30660,
      user: process.env.MYSQL_USER || "root",
      password: process.env.MYSQL_PASSWORD || "OaMduVOEs1ZXSpxmC9k5XdDK",
      database: process.env.MYSQL_DATABASE || "vigilant_bhabha",
      waitForConnections: true,
      connectionLimit: 10,
      connectTimeout: 10000,
    });
  }
  return pool;
}
