// ============================================
// Consolidated @shieldai/db package
// ============================================
// Merges functionality from:
// - @shieldai/db (Prisma v6.2.0, FieldEncryptionService)
// - @shieldsai/shared-db (singleton pattern, type exports)
// ============================================

import { PrismaClient } from '@prisma/client';
import { FieldEncryptionService } from './services/field-encryption.service';

// ============================================
// Singleton Pattern (from shared-db)
// ============================================
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 default prisma;

// ============================================
// Services (from @shieldai/db)
// ============================================
export { FieldEncryptionService };

// ============================================
// Type Exports (from shared-db)
// ============================================
export type {
  User,
  Account,
  Session,
  FamilyGroup,
  FamilyGroupMember,
  Subscription,
  WatchlistItem,
  Exposure,
  Alert,
  VoiceEnrollment,
  VoiceAnalysis,
  AnalysisJob,
  AnalysisResult,
  SpamFeedback,
  SpamRule,
  AuditLog,
  KPISnapshot,
  SecurityReport,
  WaitlistEntry,
  BlogPost,
  UserRole,
  FamilyMemberRole,
  SubscriptionTier,
  SubscriptionStatus,
  WatchlistType,
  ExposureSource,
  ExposureSeverity,
  AlertType,
  AlertSeverity,
  AlertChannel,
  FeedbackType,
  RuleType,
  RuleAction,
  ReportType,
  ReportStatus,
  AnalysisType,
  AnalysisJobStatus,
  DetectionVerdict,
} from '@prisma/client';

export * as PrismaModels from '@prisma/client';
export type { PrismaClient };
