@echo off
setlocal

set "SCRIPT_URL=https://www.hetphoenixproject.nl/AgentOrchestrator/install_latest_windows.ps1"
set "SCRIPT_PATH=%TEMP%\install_latest_windows.ps1"
set "INSTALL_ARGS="

if /I "%~1"=="clean" set "INSTALL_ARGS=-CleanInstall"
if /I "%~1"=="--clean" set "INSTALL_ARGS=-CleanInstall"
if /I "%~1"=="/clean" set "INSTALL_ARGS=-CleanInstall"

echo [AgentOrchestrator] Downloading installer script...
powershell -NoProfile -ExecutionPolicy Bypass -Command "try { iwr '%SCRIPT_URL%' -OutFile '%SCRIPT_PATH%' } catch { Write-Error $_; exit 1 }"
if errorlevel 1 (
  echo [AgentOrchestrator] Failed to download installer script.
  pause
  exit /b 1
)

echo [AgentOrchestrator] Starting installer...
powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_PATH%" %INSTALL_ARGS%
if errorlevel 1 (
  echo [AgentOrchestrator] Installer failed.
  pause
  exit /b 1
)

echo [AgentOrchestrator] Installation completed.
endlocal
