@echo off
title AI-Network Node Uninstall
setlocal enabledelayedexpansion

echo ==============================================
echo    AI-Network Node - Uninstall
echo ==============================================
echo.

set "INSTALL_DIR=%USERPROFILE%\AI-Network-Node"

if not exist "%INSTALL_DIR%" (
    echo [info] No AI-Network installation found at %INSTALL_DIR%
    echo Nothing to uninstall.
    echo.
    pause
    exit /b
)

echo Installation found at: %INSTALL_DIR%
echo.

echo [1/4] Stopping all running node processes...
powershell -Command "Stop-Process -Name 'proxy-node', 'frpc', 'proxy-agent', 'gost' -Force -ErrorAction SilentlyContinue" >nul 2>&1
powershell -Command "Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -match 'AI-Network' -and ($_.CommandLine -match 'monitor-node\.ps1' -or $_.CommandLine -match 'start-node\.ps1' -or $_.CommandLine -match 'Start Node' -or $_.CommandLine -match 'start_all\.bat' -or $_.CommandLine -match 'start_silent\.bat') } | Invoke-CimMethod -MethodName Terminate | Out-Null" >nul 2>&1
timeout /t 2 /nobreak >nul
echo    [ok] Processes stopped.

echo.
echo [2/4] Removing desktop shortcuts...
del /q "%USERPROFILE%\Desktop\Start Proxy Node.lnk" >nul 2>&1
del /q "%USERPROFILE%\Desktop\Monitor Proxy Node.lnk" >nul 2>&1
del /q "%USERPROFILE%\Desktop\Stop Proxy Node.lnk" >nul 2>&1
echo    [ok] Desktop shortcuts removed.

echo.
echo [3/4] Removing auto-start...
del /q "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\AI-Network Node.lnk" >nul 2>&1
:: Also clean up old Task Scheduler approach
schtasks /Delete /TN "AI-Network-Node-AutoStart" /F >nul 2>&1
echo    [ok] Auto-start removed.

echo.
echo [4/4] Removing installation directory...
rmdir /s /q "%INSTALL_DIR%"
echo    [ok] Directory removed.

echo.
echo ==============================================
echo    Uninstall Complete!
echo.
echo    AI-Network Node has been fully removed
echo    from your system.
echo ==============================================
echo.
pause
