@echo off
setlocal

net session >nul 2>&1
if not "%ERRORLEVEL%"=="0" (
    echo Olive uninstall requires administrator rights to remove the trusted MSIX certificate.
    echo Requesting administrator rights...
    powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%ComSpec%' -ArgumentList '/k ""%~f0"" %*' -Verb RunAs"
    exit /b 0
)

pwsh -NoProfile -ExecutionPolicy Bypass -File "%~dp0Uninstall-Olive.ps1" %*
set "OLIVE_EXIT_CODE=%ERRORLEVEL%"
echo.
if "%OLIVE_EXIT_CODE%"=="0" (
    echo Uninstall completed successfully.
) else (
    echo Uninstall failed with exit code %OLIVE_EXIT_CODE%.
)
echo Press Enter to close this window.
pause >nul
exit /b %OLIVE_EXIT_CODE%
