export function mysqlConfigured() {
  return Boolean(process.env.MYSQL_DATABASE_URL || process.env.MYSQL_HOST);
}

export async function createMySqlPool() {
  const mysql = await import("mysql2/promise");
  if (process.env.MYSQL_DATABASE_URL) {
    return mysql.createPool({
      uri: process.env.MYSQL_DATABASE_URL,
      waitForConnections: true,
      connectionLimit: 20,
      queueLimit: 0
    });
  }

  return mysql.createPool({
    host: process.env.MYSQL_HOST || "localhost",
    port: Number(process.env.MYSQL_PORT || 3306),
    user: process.env.MYSQL_USER || "root",
    password: process.env.MYSQL_PASSWORD || "",
    database: process.env.MYSQL_DATABASE || "omosala_marketplace",
    waitForConnections: true,
    connectionLimit: 20,
    queueLimit: 0
  });
}
