// Prisma 7 Configuration File
// https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/introduction/configuration

import { PrismaClient } from '@prisma/client';
import { neonConfig } from '@neondatabase/serverless';
import { Pool } from '@neondatabase/serverless';
import { PrismaNeon } from '@prisma/adapter-neon';

// EN: Get database URL from environment
// VI: Lấy database URL từ environment
const databaseUrl = process.env.DATABASE_URL;

if (!databaseUrl) {
    throw new Error('DATABASE_URL environment variable is required');
}

// EN: Configure Neon connection pool
// VI: Cấu hình connection pool cho Neon
neonConfig.webSocketConstructor = globalThis.WebSocket;

const pool = new Pool({ connectionString: databaseUrl });
const adapter = new PrismaNeon(pool);

// EN: Export configured Prisma Client
// VI: Export Prisma Client đã cấu hình
export const prisma = new PrismaClient({ adapter });

export default prisma;
