@echo off
setlocal
set PROJECT_ROOT=C:\xampp\htdocs\ddb-new
set TASK_NAME=HMH Executive Summary Refresh
set RUNNER=%PROJECT_ROOT%\tools\run_executive_summary_refresh.cmd

if not exist "%PROJECT_ROOT%\tools\run_executive_summary_refresh.ps1" (
  echo ERROR: Missing %PROJECT_ROOT%\tools\run_executive_summary_refresh.ps1
  pause
  exit /b 1
)

if not exist "C:\xampp\php\php.exe" (
  echo ERROR: Missing C:\xampp\php\php.exe
  pause
  exit /b 2
)

> "%RUNNER%" echo @echo off
>> "%RUNNER%" echo powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%PROJECT_ROOT%\tools\run_executive_summary_refresh.ps1" -ProjectRoot "%PROJECT_ROOT%" -PhpExe "C:\xampp\php\php.exe" -Hospital "njch"

echo Creating scheduled task: %TASK_NAME%
schtasks /Create /TN "%TASK_NAME%" /SC MINUTE /MO 15 /TR "%RUNNER%" /F
if errorlevel 1 (
  echo.
  echo ERROR: Could not create scheduled task. Run this CMD as Administrator.
  pause
  exit /b 3
)

echo.
echo Task created successfully.
echo Test now with:
echo schtasks /Run /TN "%TASK_NAME%"
echo.
echo Then check:
echo schtasks /Query /TN "%TASK_NAME%" /V /FO LIST
pause
