import { PrismaClient } from "@prisma/client"

// Add this for better error handling
const globalForPrisma = global as unknown as { prisma: PrismaClient }

// Create a singleton pattern for Prisma
export const prisma =
  globalForPrisma.prisma ||
  new PrismaClient({
    log: ["query", "error", "warn"],
  })

// In development, attach to global to prevent too many connections
if (process.env.NODE_ENV !== "production") {
  global.prisma = prisma
}
