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

/**
 * Prisma Client Singleton
 * Az egész alkalmazásban ugyanazt a Prisma Client példányt használjuk
 */
class DatabaseClient {
  constructor() {
    if (!DatabaseClient.instance) {
      this.prisma = new PrismaClient({
        log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
      });
      DatabaseClient.instance = this;
    }
    return DatabaseClient.instance;
  }

  getClient() {
    return this.prisma;
  }

  async disconnect() {
    await this.prisma.$disconnect();
  }
}

const databaseClient = new DatabaseClient();
Object.freeze(databaseClient);

export default databaseClient;
export const prisma = databaseClient.getClient();
