import { PrismaClient } from '@prisma/client';

// Instantiate Prisma Client
const prisma = new PrismaClient();

// Export the Prisma Client instance for use in other modules
export default prisma;

// Helper function for consistent error handling
export const handlePrismaError = (res, err, context) =>
{
  console.error(`Error ${context}:`, err.message);
  // Basic error handling, can be expanded (e.g., check for Prisma-specific error codes)
  if (err.code === 'P2025')
  { // Prisma code for record not found
    return res.status(404).json({ error: `${context}: Record not found` });
  }
  res.status(500).json({ error: `Failed to ${context}: ${err.message}` });
};