@echo off
REM Simplified MinGW Setup Script for SecondVoice

echo ========================================
echo SecondVoice - MinGW Setup (Simplified)
echo ========================================
echo.

REM Check if running as admin
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Please run as Administrator
    pause
    exit /b 1
)

REM Check/Install Chocolatey
where choco >nul 2>&1
if %errorlevel% neq 0 (
    echo [INFO] Installing Chocolatey...
    powershell -Command "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"

    echo.
    echo [SUCCESS] Chocolatey installed!
    echo Please CLOSE this window, reopen PowerShell as ADMIN, and run this script again.
    pause
    exit /b 0
)

echo [INFO] Chocolatey found

REM Install MinGW
where gcc >nul 2>&1
if %errorlevel% neq 0 (
    echo [INFO] Installing MinGW...
    choco install mingw -y
)

REM Install CMake
where cmake >nul 2>&1
if %errorlevel% neq 0 (
    echo [INFO] Installing CMake...
    choco install cmake -y --installargs 'ADD_CMAKE_TO_PATH=System'
)

REM Install Ninja
where ninja >nul 2>&1
if %errorlevel% neq 0 (
    echo [INFO] Installing Ninja...
    choco install ninja -y
)

REM Install Git
where git >nul 2>&1
if %errorlevel% neq 0 (
    echo [INFO] Installing Git...
    choco install git -y
)

REM Setup vcpkg
if not defined VCPKG_ROOT (
    if not exist "C:\vcpkg" (
        echo [INFO] Installing vcpkg...
        cd C:\
        git clone https://github.com/microsoft/vcpkg.git
        cd vcpkg
        call bootstrap-vcpkg.bat
    )
    echo [INFO] Setting VCPKG_ROOT...
    setx VCPKG_ROOT "C:\vcpkg"
    set VCPKG_ROOT=C:\vcpkg
)

echo.
echo ========================================
echo [SUCCESS] Setup Complete!
echo ========================================
echo.
echo Next: Close this window, reopen PowerShell as ADMIN
echo Then run: .\build_mingw.bat --release
echo.
pause
