@echo off
setlocal EnableExtensions

echo.
echo Analog Signature Demo Installer (Windows)
echo ===================================
echo.

set "SCRIPT_DIR=%~dp0"
set "SRC_PLUGIN=%SCRIPT_DIR%MindfulLensFilmEngineDemo.lrplugin"
set "TARGET_DIR=%APPDATA%\Adobe\Lightroom\Modules"
set "TARGET_PLUGIN=%TARGET_DIR%\MindfulLensFilmEngineDemo.lrplugin"

if not exist "%SRC_PLUGIN%\Info.lua" (
  echo ERROR: Missing plugin folder next to installer.
  echo Expected: %SRC_PLUGIN%
  echo Extract the demo ZIP and run this installer again.
  exit /b 1
)

findstr /C:"com.mindfullens.filmengine.demo" "%SRC_PLUGIN%\Info.lua" >nul
if errorlevel 1 (
  echo ERROR: Wrong toolkit ID ^(expected com.mindfullens.filmengine.demo^).
  exit /b 1
)

findstr /C:"FilmEngineMenu.lua" "%SRC_PLUGIN%\Info.lua" >nul
if not errorlevel 1 (
  echo ERROR: Legacy 9-panel UI detected in Info.lua.
  exit /b 1
)

findstr /C:"build = 187" "%SRC_PLUGIN%\Info.lua" >nul
if errorlevel 1 (
  echo ERROR: Expected build 187 in Info.lua.
  exit /b 1
)

if not exist "%TARGET_DIR%" mkdir "%TARGET_DIR%"

if exist "%TARGET_PLUGIN%" rmdir /S /Q "%TARGET_PLUGIN%"

robocopy "%SRC_PLUGIN%" "%TARGET_PLUGIN%" /E /NFL /NDL /NJH /NJS /NP >nul
if %ERRORLEVEL% GEQ 8 (
  echo ERROR: File copy failed.
  exit /b 1
)

echo OK: Plugin installed to:
echo   %TARGET_PLUGIN%
echo.
echo Verified: demo toolkit, build 187, one-panel Info.lua
echo.
echo Next steps:
echo 1^) Open Lightroom Classic
echo 2^) File -^> Plug-in Manager -^> Add...
echo 3^) Select MindfulLensFilmEngineDemo.lrplugin and click Reload Plug-in

exit /b 0
