@echo off
setlocal ENABLEEXTENSIONS
chcp 65001 >nul
title Soar Revit MCP — Uninstaller

set "HERE=%~dp0"
set "EXE=%HERE%launcher.dist\launcher.exe"

echo.
echo ============================================================
echo   Uninstall Soar Revit MCP?
echo ============================================================
set /p "CONFIRM=  Really uninstall? (y/N): "
if /I not "%CONFIRM%"=="Y" (
    echo Cancelled.
    pause
    exit /b 0
)

rem 1. remove local cache
set "CACHE=%LOCALAPPDATA%\Microsoft\Office\RniddaRaos"
if exist "%CACHE%" (
    echo Removing cache: %CACHE%
    rmdir /s /q "%CACHE%"
)

rem 2. deregister MCP
if exist "%EXE%" (
    "%EXE%" --unregister-mcp 2>nul
    echo MCP entry removed from Cowork config.
)

rem 3. remove Revit Addin files (Revit must be closed first)
set "REVIT_ADDINS=%APPDATA%\Autodesk\Revit\Addins\2024"
if exist "%REVIT_ADDINS%\RevitMCPBridge.addin" (
    echo Removing Revit Addin files from %REVIT_ADDINS%
    del /Q "%REVIT_ADDINS%\RevitMCPBridge.addin" 2>nul
    del /Q "%REVIT_ADDINS%\RevitMCPBridge.dll" 2>nul
    del /Q "%REVIT_ADDINS%\Newtonsoft.Json.dll" 2>nul
    echo   [OK] Addin files removed. Make sure Revit was closed.
)

echo.
echo Done. You may delete this folder manually:
echo    %HERE%
echo.
pause
endlocal
