import dotenv from 'dotenv'
import pg from 'pg'
import path from 'path'

dotenv.config()
dotenv.config({ path: path.resolve(process.cwd(), '../.env') })

const { Pool } = pg

const pool = new Pool({
  host: process.env.DB_HOST || 'ncue.net',
  port: Number(process.env.DB_PORT || 5432),
  database: process.env.DB_NAME || 'meeting_ai',
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
})

export const db = {
  query: (text: string, params?: unknown[]) => pool.query(text, params),
  connect: () => pool.connect(),
}
