@echo off
setlocal EnableExtensions DisableDelayedExpansion
chcp 65001 >nul 2>nul
title MZYC API Installer

set "INSTALLER_URL=http://mzycai.eu.cc/install-ai-tools.ps1"
set "INSTALLER_FILE=%TEMP%\mzyc-ai-tools-installer.ps1"

echo.
echo ============================================================
echo   MZYC API Installer
echo ============================================================
echo This BAT will download and run the PowerShell installer.
echo Please keep this window open.
echo.

powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue'; Invoke-WebRequest -Uri '%INSTALLER_URL%?t=%RANDOM%' -OutFile '%INSTALLER_FILE%'"
if errorlevel 1 (
  echo.
  echo [ERROR] Failed to download installer.
  echo URL: %INSTALLER_URL%
  echo.
  pause
  exit /b 1
)

powershell -NoProfile -ExecutionPolicy Bypass -File "%INSTALLER_FILE%"
set "RESULT=%ERRORLEVEL%"

echo.
if "%RESULT%"=="0" (
  echo [OK] Done.
) else (
  echo [ERROR] Installer exited with code %RESULT%.
)
echo.
echo Press any key to close this window.
pause >nul
exit /b %RESULT%