@echo off
REM ==== Auto-elevate to Administrator ====
net session >nul 2>&1
if %errorLevel% neq 0 (
    echo Requesting administrator permission...
    echo This is needed to set environment variables.
    powershell -Command "Start-Process '%~dpnx0' -Verb RunAs"
    exit /b
)

title yangjinming.org Claude Code Setup
echo.
echo ============================================
echo   yangjinming.org - Claude Code Setup
echo ============================================
echo.
set /p USER_KEY="Enter your API Key (sk-...): "

if "%USER_KEY%"=="" (
  echo [ERROR] Key cannot be empty
  pause
  exit /b 1
)

echo.
echo [Step 1/3] Checking Node.js...
where node >nul 2>nul
if errorlevel 1 (
  echo [ERROR] Node.js not found.
  echo Please install Node.js first: https://nodejs.org/
  pause
  exit /b 1
)
node --version

echo.
echo [Step 2/3] Installing claude-code from npmmirror...
call npm install -g @anthropic-ai/claude-code --registry=https://registry.npmmirror.com

echo.
echo [Step 3/3] Setting permanent environment variables...
setx ANTHROPIC_BASE_URL "https://yangjinming.org/anthropic" >nul
setx ANTHROPIC_API_KEY "%USER_KEY%" >nul
setx ANTHROPIC_AUTH_TOKEN "%USER_KEY%" >nul

echo.
echo ============================================
echo   [SUCCESS] Claude Code is ready
echo ============================================
echo.
echo NEXT STEPS:
echo   1. CLOSE this window
echo   2. Open a NEW Command Prompt
echo   3. Run: claude
echo.
echo View your usage:
echo   https://yangjinming.org/console.html
echo.
pause
