import pg from "pg";

const globalForPbx = globalThis as unknown as {
  pbxPool: pg.Pool | undefined;
};

export const pbxPool =
  globalForPbx.pbxPool ??
  new pg.Pool({
    connectionString: process.env.PBX_DATABASE_URL,
    max: 5,
    idleTimeoutMillis: 30000,
    connectionTimeoutMillis: 5000,
  });

if (process.env.NODE_ENV !== "production") globalForPbx.pbxPool = pbxPool;

export default pbxPool;
