import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "@/generated/prisma/client";

/**
 * The one place a PrismaClient is constructed (app and CLI scripts alike).
 *
 * The session timezone is pinned to UTC on purpose. The pg driver adapter
 * sends and parses timestamps as zone-less UTC wall-clock text, so under any
 * other session timezone (a local Postgres defaults to the machine's, e.g.
 * Asia/Kolkata) every written Date lands shifted by the UTC offset and every
 * raw-query read is shifted back the other way. Pinning UTC makes stored
 * values true instants regardless of how the server is configured.
 */
export function createPrismaClient(connectionString: string): PrismaClient {
  const adapter = new PrismaPg({ connectionString, options: "-c timezone=UTC" });
  return new PrismaClient({ adapter });
}
