import mysql from "mysql2/promise";
import { loadSwiEnv } from "./loadEnv.js";

loadSwiEnv();

const host = process.env.MYSQL_HOST || process.env.DB_HOST || "127.0.0.1";
const port = Number(process.env.MYSQL_PORT || process.env.DB_PORT || 3306);
const user = process.env.MYSQL_USER || process.env.DB_USER || "root";
const password =
  process.env.MYSQL_PASSWORD !== undefined
    ? process.env.MYSQL_PASSWORD
    : process.env.DB_PASSWORD ?? "";

/** Single shared MySQL schema for EHS apps (not overridable). */
const HSE_DATABASE = "hse";

export const pool = mysql.createPool({
  host,
  port,
  user,
  password,
  database: HSE_DATABASE,
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0,
});
