@echo off
setlocal

REM ============================================================
REM Deploy script. Tries to deploy with current user privileges first
REM (no UAC). Only elevates and retries if normal deployment fails
REM (e.g. target files are owned by Administrator).
REM Actual deployment logic is in deploy-body.ps1.
REM ============================================================

set "SCRIPT_DIR=%~dp0"

REM First attempt: deploy with current user permissions
pwsh -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%deploy-body.ps1"
if %ERRORLEVEL% EQU 0 (
    echo Deployment succeeded without elevation.
    exit /b 0
)

REM Normal deploy failed. Elevate and retry.
echo Deployment failed with current user permissions. Retrying with administrator rights...
pwsh -Command "Start-Process -FilePath 'pwsh.exe' -ArgumentList '-NoProfile','-ExecutionPolicy','Bypass','-File','\"%SCRIPT_DIR%deploy-body.ps1\"' -Verb RunAs -Wait"

if errorlevel 1 (
    echo Deployment failed.
    exit /b 1
)
echo Plugin deployed successfully.
exit /b 0
