@echo off

SET SCRIPT_DIR=%~dp0
SET EXE_PATH=%SCRIPT_DIR%DDNSUpdater.exe
SET NSSM_PATH=%SCRIPT_DIR%nssm.exe

REM Logs directory
SET LOG_DIR=%SCRIPT_DIR%logs

IF NOT EXIST "%LOG_DIR%" mkdir "%LOG_DIR%"

REM Remove old service (ignore errors)
"%NSSM_PATH%" remove TrizTechDDNSUpdaterService confirm

REM Install service
"%NSSM_PATH%" install TrizTechDDNSUpdaterService "%EXE_PATH%"

REM Set auto-start
"%NSSM_PATH%" set TrizTechDDNSUpdaterService Start SERVICE_AUTO_START

REM 🔥 Redirect output to logs
"%NSSM_PATH%" set TrizTechDDNSUpdaterService AppStdout "%LOG_DIR%\output.log"
"%NSSM_PATH%" set TrizTechDDNSUpdaterService AppStderr "%LOG_DIR%\error.log"

REM Optional: rotate logs (prevent huge files)
"%NSSM_PATH%" set TrizTechDDNSUpdaterService AppRotateFiles 1
"%NSSM_PATH%" set TrizTechDDNSUpdaterService AppRotateOnline 1

REM Start service
"%NSSM_PATH%" start TrizTechDDNSUpdaterService

echo Service installed with logging enabled.
pause
