import { createMySqlPool, mysqlConfigured } from "../db/mysql-adapter.js";

export async function connectDatabase() {
  if (!mysqlConfigured()) {
    console.warn("MySQL is not configured. API will run with local fallback data.");
    return null;
  }

  try {
    const pool = await createMySqlPool();
    await pool.query("SELECT 1");
    console.log("MySQL connected");
    return pool;
  } catch (error) {
    console.warn("MySQL unavailable. API will run with local fallback data.", error.message);
    return null;
  }
}
