export { PrismaClient, Prisma } from '@prisma/client';
export type {
  User,
  UserCredential,
  UserSession,
  EmailVerificationToken,
  PasswordResetToken,
  TotpCredential,
  RecoveryCode,
  PlatformRole,
  UserPlatformRole,
  GameServer,
  GameServerStateTransition,
  GameNode,
  GameNodeHeartbeat,
  Plan,
  FeatureFlag,
  SystemSetting,
  AuditEvent,
  JobRecord,
} from '@prisma/client';

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

const globalForPrisma = globalThis as unknown as {
  prisma: PrismaClient | undefined;
};

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

if (process.env['NODE_ENV'] !== 'production') {
  globalForPrisma.prisma = prisma;
}

export function createPrismaClient(): PrismaClient {
  return new PrismaClient();
}
