@echo off
REM =====================================================================
REM  build-counter-helper.cmd
REM
REM  Produces the shippable Windows binary. Run on a Windows machine with
REM  the .NET 8 SDK and internet access, from the CounterHelper folder.
REM
REM  =================================================================
REM  WHY THIS IS NOT BUILT WITH THE REST OF THE PLATFORM
REM  =================================================================
REM
REM  Everything else runs on the Linux server and is built there. This
REM  one component cannot be: it targets net8.0-windows and calls
REM  winspool.drv, which exists only on Windows. The build environment
REM  compiles it as a portability check (Check.csproj, plain net8.0) and
REM  the raw-printing path has therefore NEVER EXECUTED there.
REM
REM  That is the honest state of it. This script is how the real binary
REM  gets made, and the checklist at the end is what has to happen before
REM  anyone trusts it.
REM =====================================================================

setlocal
echo.
echo  Counter Helper — Windows build
echo  ==============================
echo.

where dotnet >nul 2>&1
if %errorlevel% neq 0 (
  echo  The .NET 8 SDK is not installed.
  echo  https://dotnet.microsoft.com/download/dotnet/8.0
  exit /b 1
)

if not exist "CounterHelper.csproj" (
  echo  Run this from the CounterHelper folder.
  exit /b 1
)

REM  Self-contained and single-file: a chemist's counter has no .NET
REM  runtime and nobody is installing one over a shop's broadband.
echo  Building self-contained win-x64...
dotnet publish CounterHelper.csproj ^
  -c Release ^
  -r win-x64 ^
  --self-contained true ^
  -p:PublishSingleFile=true ^
  -p:IncludeNativeLibrariesForSelfExtract=true ^
  -p:DebugType=none ^
  -o publish

if %errorlevel% neq 0 (
  echo.
  echo  Build failed.
  exit /b 1
)

copy /Y install-counter-helper.cmd publish\ >nul 2>&1
copy /Y README.md publish\ >nul 2>&1

echo.
echo  Built: publish\CounterHelper.exe
echo.
echo  BEFORE THIS GOES TO A SHOP — none of it can be done from Linux:
echo.
echo    [ ] /v1/printers lists the printers Windows actually has
echo    [ ] a test slip reaches paper on a real 80mm thermal
echo    [ ] a test slip reaches paper on a genuinely old LX-300,
echo        sourced from a shop, not new stock — clone firmware varies
echo        and that is where the surprises live
echo    [ ] the drawer kick fires
echo    [ ] kill the service mid-queue, restart it, queued jobs print
echo    [ ] unplug the printer, bill anyway, plug it back in, the slip
echo        comes out — the counter must never wait on hardware
echo    [ ] TIMED AGAINST THE INCUMBENT on the same machine in the same
echo        shop. If the slip is slower than what the chemist already
echo        has, stop the roadmap and fix that first.
echo.
endlocal
exit /b 0
