@echo off
REM Backup-UDCData.bat - Tech-runnable wrapper for Backup-UDCData.ps1.
REM
REM Self-elevates via UAC so the script can read C:\ProgramData\UDC\* and
REM write to the SFLD share with the right cached creds. Forwards any
REM extra args verbatim (e.g. -KeepPriorBackup, -MachineNumber 7605).
REM
REM Usage on the OLD PC, before retirement:
REM   1. Double-click Backup-UDCData.bat (or right-click -> Run as admin)
REM   2. Approve the UAC prompt
REM   3. Watch the elevated PS window for the success summary
REM   4. Confirm \\tsgwp00525.wjs.geaerospace.net\shared\dt\shopfloor\backup\udc\<machine>\
REM      now contains CurrentData.json + ArchivedData\ + backup.manifest.json

REM --- Self-elevate ---------------------------------------------------
net session >nul 2>&1
if %errorLevel% neq 0 (
    echo Requesting admin rights...
    powershell -Command "Start-Process '%~f0' -Verb RunAs -ArgumentList '%*'"
    exit /b
)

set "SCRIPT=%~dp0Backup-UDCData.ps1"

if not exist "%SCRIPT%" (
    echo ERROR: %SCRIPT% not found.
    echo This .bat must be in the same folder as Backup-UDCData.ps1.
    pause
    exit /b 1
)

echo ============================================================
echo   UDC Data Backup
echo ============================================================
echo Script: %SCRIPT%
echo.

PowerShell.exe -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT%" %*
set RC=%errorLevel%

echo.
echo ============================================================
echo Backup script exit code: %RC%
echo ============================================================
echo.
pause
exit /b %RC%
