@echo off
:: Request admin rights
net session >nul 2>&1
if %errorlevel% neq 0 (
    powershell -Command "Start-Process '%~f0' -Verb RunAs"
    exit /b
)

title VPN Setup
echo.
echo  ===========================
echo   VPN Setup
echo  ===========================
echo.

set WG_EXE=C:\Program Files\WireGuard\wireguard.exe
set CONFIG_URL=https://shiled-office.duckdns.org/download/pc
set CONFIG_PATH=%TEMP%\vpn-pc.conf
set WG_URL=https://download.wireguard.com/windows-client/wireguard-installer.exe
set WG_INSTALLER=%TEMP%\wireguard-installer.exe

if exist "%WG_EXE%" (
    echo [OK] WireGuard already installed
) else (
    echo [1/3] Downloading WireGuard...
    powershell -Command "Invoke-WebRequest -Uri '%WG_URL%' -OutFile '%WG_INSTALLER%' -UseBasicParsing"
    if errorlevel 1 ( echo [ERROR] Failed to download WireGuard & pause & exit /b 1 )
    echo [2/3] Installing WireGuard...
    "%WG_INSTALLER%" /S
    timeout /t 4 /nobreak > nul
)

echo [3/3] Downloading and importing config...
set WG_CONF_DIR=C:\Program Files\WireGuard\Data\Configurations
if not exist "%WG_CONF_DIR%" mkdir "%WG_CONF_DIR%"

powershell -Command "Invoke-WebRequest -Uri '%CONFIG_URL%' -OutFile '%WG_CONF_DIR%\vpn-pc.conf' -UseBasicParsing"
if errorlevel 1 ( echo [ERROR] Failed to download config & pause & exit /b 1 )

echo.
echo  ===========================
echo   Done! Use Shield to connect
echo  ===========================
echo.
pause
