import mysql from "mysql2/promise";
import dotenv from "dotenv";
import { fileURLToPath } from "url";
import path from "path";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
dotenv.config({ path: path.join(__dirname, "..", "..", ".env") });

const pool = mysql.createPool({
  host: process.env.DB_HOST ?? "127.0.0.1",
  port: Number(process.env.DB_PORT ?? 3307),
  user: process.env.DB_USER ?? "darkwatch",
  password: process.env.DB_PASSWORD ?? "darkwatch_dev",
  database: process.env.DB_NAME ?? "darkwatch",
  waitForConnections: true,
  connectionLimit: 10,
  timezone: "+00:00",
});

export default pool;
