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

// Singleton pattern for Prisma Client
const globalForPrisma = globalThis as unknown as {
  prisma: PrismaClient | undefined;
};

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

if (process.env.NODE_ENV === 'development') {
  globalForPrisma.prisma = prisma;
}

// Export types from generated client
export type {
  User,
  Account,
  Session,
  FamilyGroup,
  FamilyGroupMember,
  Subscription,
  WatchlistItem,
  Exposure,
  Alert,
  VoiceEnrollment,
  VoiceAnalysis,
  SpamFeedback,
  SpamRule,
  AuditLog,
  KPISnapshot,
  UserRole,
  FamilyMemberRole,
  SubscriptionTier,
  SubscriptionStatus,
  WatchlistType,
  ExposureSource,
  ExposureSeverity,
  AlertType,
  AlertSeverity,
  AlertChannel,
  FeedbackType,
  RuleType,
  RuleAction,
} from '@prisma/client';

export * as PrismaModels from '@prisma/client';
