@echo off
setlocal
chcp 65001 >nul
set "AGENT_DIR=%LOCALAPPDATA%\MedOnix\Diagnostics"
set "AGENT_FILE=%AGENT_DIR%\Collect-MedOnixDiagnostics.ps1"

if not exist "%AGENT_DIR%" mkdir "%AGENT_DIR%"
if errorlevel 1 goto :failed

curl.exe --fail --silent --show-error --location --proto "=https" --tlsv1.2 "https://chat.medonix.net/diagnostics-agent/Collect-MedOnixDiagnostics.ps1" --output "%AGENT_FILE%"
if errorlevel 1 goto :failed

powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%AGENT_FILE%" -Install
if errorlevel 1 goto :failed

echo.
echo Installation completed. Return to MedOnix Chat and click Diagnostics again.
pause
exit /b 0

:failed
echo.
echo MedOnix Diagnostics installation failed. Take a screenshot of this window and contact the system owner.
pause
exit /b 1
