#!/usr/bin/env node

/**
 * Preinstall Script - Global Installation Warning
 *
 * RestForge mendukung instalasi global maupun lokal.
 * Local install direkomendasikan untuk version pinning per project.
 * Global install aman digunakan karena project isolation sudah aktif.
 *
 * Script ini menampilkan warning informatif saat global install,
 * tanpa memblok proses instalasi.
 */

const YELLOW = '\x1b[33m';
const CYAN = '\x1b[36m';
const GREEN = '\x1b[32m';
const RESET = '\x1b[0m';
const BOLD = '\x1b[1m';

if (process.env.npm_config_global) {
    console.log('');
    console.log(YELLOW + 'â•”â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•—' + RESET);
    console.log(YELLOW + 'â•‘                                                                â•‘' + RESET);
    console.log(YELLOW + 'â•‘  ' + BOLD + 'âš  NOTE: Installing RestForge globally' + RESET + YELLOW + '                    â•‘' + RESET);
    console.log(YELLOW + 'â•‘                                                                â•‘' + RESET);
    console.log(YELLOW + 'â•šâ•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•' + RESET);
    console.log('');
    console.log(GREEN + '  Global install is supported.' + RESET);
    console.log('  Project isolation ensures each project has separate:');
    console.log('    â€¢ Redis keys, BullMQ queues, Kafka consumer groups');
    console.log('    â€¢ Log, export, and upload directories');
    console.log('');
    console.log(YELLOW + '  Recommendation:' + RESET + ' Local install is preferred for version pinning.');
    console.log('');
    console.log(CYAN + '  Local install:' + RESET);
    console.log('    ' + BOLD + 'npm install @restforgejs/platform' + RESET);
    console.log('');
    console.log(CYAN + '  Usage (both global and local):' + RESET);
    console.log('    ' + BOLD + 'npx restforge serve --project=myproject --config=mydb.env' + RESET);
    console.log('');
} else {
    console.log(GREEN + 'âœ“' + RESET + ' Installing RestForge locally...');
}

process.exit(0);
