@echo off
:: VELA Agent — Windows installer wrapper.
:: Double-click from File Explorer or run from cmd. Internally invokes
:: install.ps1 with PowerShell so users don't have to think about
:: execution policy or PowerShell at all.
::
:: Stays open on completion (and on error) so the user can read the
:: link code or any failure message — vs the bare .exe which flashes
:: closed instantly.

setlocal enabledelayedexpansion

title VELA Agent - Windows Installer
color 0F

cls
echo.
echo   ============================================================
echo                  VELA Agent - Windows Installer
echo   ============================================================
echo.
echo   The desktop agent lets VELA encrypt and send files when they
echo   land in a folder, save received files automatically, and run
echo   AI workflows on this computer.
echo.
echo   - No admin rights required (installs into your user profile).
echo   - About 4 MB. The download is verified by SHA-256.
echo   - You can uninstall any time from PowerShell.
echo.

:CONFIRM_INSTALL
choice /C YN /N /M "Install VELA agent now? [Y/N]: "
if errorlevel 2 (
    echo.
    echo   Cancelled. Press any key to close.
    pause >nul
    endlocal & exit /b 0
)

echo.
echo   Should the agent run automatically every time you log into
echo   Windows? Recommended - it stays in the background, hidden,
echo   so transfers and workflows continue even after you reboot.
echo.

:CONFIRM_AUTOSTART
choice /C YN /N /M "Run at every login? [Y/N]: "
if errorlevel 2 (
    set "AUTO_FLAG="
) else (
    set "AUTO_FLAG=-Autostart"
)

echo.
echo   ------------------------------------------------------------
echo   Downloading and installing...
echo   ------------------------------------------------------------
echo.

powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "& ([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing https://vela.netup.global/install.ps1).Content)) %AUTO_FLAG%"

set "PS_EXIT=%ERRORLEVEL%"
echo.
echo   ------------------------------------------------------------
if %PS_EXIT% EQU 0 (
    echo   Install complete.
    echo.
    if defined AUTO_FLAG (
        echo   The agent is running in the background and will start
        echo   automatically every time you log in.
    ) else (
        echo   Run the agent any time by typing 'vela-agent' in a
        echo   PowerShell window, or re-run this installer with
        echo   "Run at every login" turned on.
    )
    echo.
    echo   Next: open https://vela.netup.global/app/ and link this
    echo   device under Settings - Devices using the 6-digit code
    echo   the agent prints.
) else (
    echo   Install failed. Read the messages above for the cause.
    echo.
    echo   Most common reasons:
    echo     - No internet connection.
    echo     - Windows Defender flagged the unsigned .exe ^(unblock
    echo       it in Defender then re-run this installer^).
    echo     - PowerShell is missing or disabled by group policy.
)
echo   ------------------------------------------------------------
echo.
echo   Press any key to close this window.
pause >nul
endlocal
