$ErrorActionPreference = "Stop"

Write-Host "========================================="
Write-Host "Downloading and Installing Dependencies..."
Write-Host "========================================="

# 1. Download and install Node.js
Write-Host "`n[1/3] Downloading Node.js..."
$nodeUrl = "https://nodejs.org/dist/v20.11.1/node-v20.11.1-x64.msi"
$nodeMsi = "$env:TEMP\nodejs.msi"
Invoke-WebRequest -Uri $nodeUrl -OutFile $nodeMsi
Write-Host "Installing Node.js..."
Start-Process msiexec.exe -Wait -ArgumentList "/i $nodeMsi /quiet /norestart"
Write-Host "Node.js installed."

# 2. Download and install Java 17
Write-Host "`n[2/3] Downloading Java 17..."
$javaUrl = "https://aka.ms/download-jdk/microsoft-jdk-17.0.10-windows-x64.msi"
$javaMsi = "$env:TEMP\jdk17.msi"
Invoke-WebRequest -Uri $javaUrl -OutFile $javaMsi
Write-Host "Installing Java 17..."
Start-Process msiexec.exe -Wait -ArgumentList "/i $javaMsi /quiet /norestart"
Write-Host "Java 17 installed."

# 3. Download and install Docker Desktop
Write-Host "`n[3/3] Downloading Docker Desktop..."
$dockerUrl = "https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe"
$dockerExe = "$env:TEMP\DockerDesktopInstaller.exe"
Invoke-WebRequest -Uri $dockerUrl -OutFile $dockerExe
Write-Host "Installing Docker Desktop (this may take a few minutes)..."
Start-Process $dockerExe -Wait -ArgumentList "install --quiet"
Write-Host "Docker Desktop installed."

Write-Host "`n========================================="
Write-Host "Installation Complete!"
Write-Host "IMPORTANT: Please RESTART your computer now."
Write-Host "========================================="
Write-Host "Press any key to exit..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
