@echo off
REM UClaude Updater — automatic Claude Code patch updater
REM Usage: claude\uclaude_update.bat [--check] [--force] [--settings-only]

setlocal enabledelayedexpansion
set "SCRIPT_DIR=%~dp0"
cd /d "%SCRIPT_DIR%\.."

REM ---- Check prerequisites ----

where git >nul 2>&1
if errorlevel 1 (
    echo ERROR: git not found.
    echo Install: winget install Git.Git
    echo    or: https://git-scm.com/download/win
    pause
    exit /b 1
)

where python >nul 2>&1
if errorlevel 1 (
    where python3 >nul 2>&1
    if errorlevel 1 (
        echo ERROR: Python not found.
        echo Install: winget install Python.Python.3.12
        echo    or: https://www.python.org/downloads/
        pause
        exit /b 1
    )
)

where node >nul 2>&1
if errorlevel 1 (
    echo WARNING: Node.js not found.
    echo Install: winget install OpenJS.NodeJS.V24
    echo    or: https://nodejs.org/
) else (
    for /f "tokens=1 delims=." %%A in ('node -v') do set "NODE_MAJOR=%%A"
    set "NODE_MAJOR=!NODE_MAJOR:v=!"
    if !NODE_MAJOR! LSS 24 (
        echo WARNING: Node.js v!NODE_MAJOR! found, need v24+
        echo Upgrade: winget install OpenJS.NodeJS.V24
        echo    or: https://nodejs.org/
    )
)

REM ---- Pull latest artifacts ----
git pull --quiet 2>nul

REM ---- Run updater ----

REM Try python3 first, fallback to python
where python3 >nul 2>&1
if not errorlevel 1 (
    python3 claude\uclaude_updater.py %*
) else (
    python claude\uclaude_updater.py %*
)

if errorlevel 1 (
    echo.
    echo If you see permission errors, run this script as Administrator.
    pause
)
