# PowerShell Java Environment Switch - {{env_name}}
# Generated by fnva

# Remove existing Java paths from PATH first
$pathParts = $env:PATH -split ';'
$cleanPath = @()
foreach ($part in $pathParts) {
    if ($part -notmatch 'java' -and $part -notmatch 'jdk') {
        $cleanPath += $part
    }
}

# Set new JAVA_HOME and update PATH
$env:JAVA_HOME = "{{escape_backslash java_home}}"
$env:PATH = "{{escape_backslash java_bin}};" + ($cleanPath -join ';')

# Set fnva environment tracking
$env:FNVA_CURRENT_JAVA = "{{env_name}}"
$env:FNVA_ENV_TYPE = "Java"

# Verify the switch
Write-Host "✅ Switched to Java environment: {{env_name}}" -ForegroundColor Green
Write-Host "📁 JAVA_HOME: $env:JAVA_HOME" -ForegroundColor Yellow
Write-Host "🔍 Java Version:" -ForegroundColor Cyan
try {
    & "{{escape_backslash java_bin}}\\java.exe" -version 2>&1 | ForEach-Object { Write-Host "   $_" -ForegroundColor Gray }
} catch {
    Write-Host "   Failed to get Java version" -ForegroundColor Red
}