import { PrismaClient } from '@prisma/client';
import { appConfig } from '../config';

const globalForPrisma = global as unknown as { prisma: PrismaClient };

export const prisma =
  globalForPrisma.prisma ||
  new PrismaClient({
    log: appConfig.environment === 'development' ? ['query', 'error', 'warn'] : ['error'],
  });

if (appConfig.environment !== 'production') globalForPrisma.prisma = prisma;