#!/bin/bash

# RARN Installation Script
echo "🚀 Installing RARN - Universal Package Manager..."

# Check Node.js
if ! command -v node &> /dev/null; then
    echo "❌ Node.js is required but not installed."
    echo "Please install Node.js 16+ from https://nodejs.org/"
    exit 1
fi

# Check Node version
NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$NODE_VERSION" -lt 16 ]; then
    echo "❌ Node.js 16+ is required. Current version: $(node -v)"
    exit 1
fi

# Install globally
echo "📦 Installing RARN globally..."
npm install -g rarn

# Verify installation
if command -v rarn &> /dev/null; then
    echo "✅ RARN installed successfully!"
    echo "📍 Version: $(rarn --version)"
    echo ""
    echo "🎉 You can now use RARN! Try:"
    echo "   rarn init"
    echo "   rarn install express python:numpy"
    echo "   rarn env create myproject"
else
    echo "❌ Installation failed. Please check the error messages above."
    exit 1
fi