@echo off
setlocal EnableExtensions
title Helgi OS Mission Control Setup
color 0B
echo ============================================================
echo  HELGI OS - MISSION CONTROL SETUP
echo ============================================================
echo.
set "BASE=https://helgi-os.onrender.com"
set "TMPDIR=%TEMP%\HelgiMissionControlSetup"
if exist "%TMPDIR%" rmdir /s /q "%TMPDIR%"
mkdir "%TMPDIR%" >nul 2>&1

echo Downloading signed-infrastructure bootstrap files from Mission Control...
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; $b='%BASE%/downloads'; $d='%TMPDIR%'; Invoke-WebRequest -UseBasicParsing ($b+'/HelgiLocalAgent.ps1') -OutFile (Join-Path $d 'HelgiLocalAgent.ps1'); Invoke-WebRequest -UseBasicParsing ($b+'/Invoke-ClaudeCode.ps1') -OutFile (Join-Path $d 'Invoke-ClaudeCode.ps1'); Invoke-WebRequest -UseBasicParsing ($b+'/projects.example.json') -OutFile (Join-Path $d 'projects.example.json'); Invoke-WebRequest -UseBasicParsing ($b+'/Install-HelgiMissionControl.ps1') -OutFile (Join-Path $d 'Install-HelgiMissionControl.ps1')"
if errorlevel 1 goto :fail

echo Installing Mission Control shortcuts and Local Agent foundation...
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%TMPDIR%\Install-HelgiMissionControl.ps1" -PortalUrl "%BASE%"
if errorlevel 1 goto :fail

echo.
echo ============================================================
echo  MISSION CONTROL FOUNDATION INSTALLED
echo ============================================================
echo.
echo Desktop shortcuts have been created.
echo The Local Agent will remain disconnected until its secure token
echo is configured in Mission Control and on this PC.
echo.
start "" "%BASE%/ops"
echo Press any key to close.
pause >nul
exit /b 0

:fail
echo.
color 0C
echo MISSION CONTROL SETUP FAILED.
echo No source project data was deleted or modified by this bootstrap.
echo Temporary setup folder: %TMPDIR%
echo.
pause
exit /b 1
