# App image: install the host-built survey wheel + private dependency
# wheels from docker/wheels/. Public deps still come from PyPI.
#
# Prepare wheels on the host (Python >= 3.12 venv, private packages visible):
#   make frontend-static
#   powershell -File docker/build-wheels.ps1
#
# openroland-crs requires Python >= 3.12.

FROM python:3.14.6-slim AS runtime
WORKDIR /app

# Host-built wheels (openroland-survey-core, openroland-crs, romgeo, optional extractors).
# Must exist before ``docker compose build`` — see ``make d-local``.
COPY docker/wheels/ /wheels/

RUN set -eu; \
    echo "Wheels available:"; ls -1 /wheels || true; \
    ls /wheels/openroland_crs-*.whl >/dev/null 2>&1 \
      || { echo "Missing openroland-crs wheel. Run: powershell -File docker/build-wheels.ps1" >&2; exit 1; }; \
    ls /wheels/romgeo-*.whl >/dev/null 2>&1 \
      || { echo "Missing romgeo wheel. Run: powershell -File docker/build-wheels.ps1" >&2; exit 1; }; \
    ls /wheels/openroland_survey-*.whl >/dev/null 2>&1 \
      || { echo "Missing openroland-survey-core wheel. Run: make frontend-static && powershell -File docker/build-wheels.ps1" >&2; exit 1; }; \
    pip install --no-cache-dir --upgrade pip; \
    pip install --no-cache-dir --find-links=/wheels \
      "openroland-survey-core[cli,web,cad]"; \
    pip install --no-cache-dir --find-links=/wheels \
      openroland-cube openroland-rw5 openroland-jxl \
      || echo "WARN: optional extractor wheels missing; convert jobs need them"

EXPOSE 8000

ENV SISCADRO_DB=/data/production.gpkg
ENV SISCADRO_CRS=EPSG:3844

CMD ["sh", "-c", \
     "openroland-survey-core web --db \"$SISCADRO_DB\" --host 0.0.0.0 --port 8000 \
      --crs \"$SISCADRO_CRS\""]
