import { isMemoryMode } from '../config/persistence.js';
let prismaClient = null;
export async function getPrismaClient() {
    if (isMemoryMode()) {
        throw new Error('Cannot initialize Prisma client in memory mode. ' +
            'Set GATEWAY_PERSISTENCE=postgres to use PostgreSQL.');
    }
    if (!prismaClient) {
        const prismaModule = await import('@prisma/client');
        const PrismaClientConstructor = prismaModule.PrismaClient || prismaModule.default?.PrismaClient;
        if (!PrismaClientConstructor) {
            throw new Error('PrismaClient not found in @prisma/client. Make sure Prisma client is generated: pnpm db:generate');
        }
        prismaClient = new PrismaClientConstructor({
            log: process.env['NODE_ENV'] === 'development'
                ? ['query', 'error', 'warn']
                : ['error'],
        });
    }
    return prismaClient;
}
export async function disconnectPrisma() {
    if (prismaClient) {
        await prismaClient.$disconnect();
        prismaClient = null;
    }
}
export function isPrismaInitialized() {
    return prismaClient !== null;
}
//# sourceMappingURL=prisma.js.map