@echo off
set "DIR=%~dp0"
if "%DIR:~-1%"=="\" set "DIR=%DIR:~0,-1%"

rem ===== Settings =====
set "SERVICE_NAME=DataFurtBridge"
set "CONFIG_PATH=./config.toml"
set "LOG_PATH=./logs"
set "LOG_LEVEL=information"
set "RESTART_DELAY_MS=5000"
set "RESET_SECONDS=86400"

rem Elevate to Administrator if needed.
net session >nul 2>&1 || (powershell -NoProfile -Command "Start-Process '%~f0' -Verb RunAs" & exit /b)

rem Recreate service to apply changes from this folder.
sc stop %SERVICE_NAME% >nul 2>&1
sc delete %SERVICE_NAME% >nul 2>&1
sc create %SERVICE_NAME% binPath= "\"%DIR%\df-bridge.exe\" --config \"%CONFIG_PATH%\" --log-files \"%LOG_PATH%\" --log-level %LOG_LEVEL%" start= auto

rem Restart policy: on crash restart after delay, reset failure counter after 24h.
sc failure %SERVICE_NAME% reset= %RESET_SECONDS% actions= restart/%RESTART_DELAY_MS%/restart/%RESTART_DELAY_MS%/restart/%RESTART_DELAY_MS%
sc failureflag %SERVICE_NAME% 1
sc start %SERVICE_NAME%
pause
