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

class DatabaseConnection {
  constructor() {
    this.prisma = new PrismaClient({
      log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
    });
  }

  async connect() {
    try {
      await this.prisma.$connect();
      console.log('✅ Database connected successfully');
    } catch (error) {
      console.error('❌ Database connection failed:', error);
      throw error;
    }
  }

  async disconnect() {
    await this.prisma.$disconnect();
    console.log('🔌 Database disconnected');
  }

  getClient() {
    return this.prisma;
  }
}

export default new DatabaseConnection();
