# Builds the per-release documentation without touching the host:
#  1) Pyreverse (Pylint) + Graphviz draw class and module diagrams from the source code
#  2) pdflatex compiles release-notes.tex with the version, commit, test log, and diagrams
#  3) the "out" stage holds only the results; Jenkins exports it with --output type=local
# Context: pricing/   Usage: see the "Docs: architecture + LaTeX" stage in pricing/Jenkinsfile
FROM python:3.13-slim@sha256:e48f59cdba69a3cbd9ed2cf0f348d90d45a8d350d98134cf1070bc106ee9ed90 AS uml
RUN apt-get update && apt-get install -y --no-install-recommends graphviz \
 && rm -rf /var/lib/apt/lists/* && pip install --no-cache-dir pylint==3.3.7
WORKDIR /src
COPY app/app.py app/test_app.py ./app/
RUN mkdir -p /out && pyreverse -o png -p pricing -d /out app/app.py app/test_app.py

FROM debian:trixie-slim AS tex
RUN apt-get update && apt-get install -y --no-install-recommends \
      texlive-latex-base texlive-latex-recommended \
 && rm -rf /var/lib/apt/lists/*
WORKDIR /doc
ARG SEMVER=0.0.0 COMMIT=unknown BRANCH=unknown BUILD_URL=unknown BUILD_DATE=unknown
COPY docs/release-notes.tex docs/unittest.log ./
COPY --from=uml /out/ ./
RUN sed -i -e "s|@SEMVER@|${SEMVER}|g" -e "s|@COMMIT@|${COMMIT}|g" -e "s|@BRANCH@|${BRANCH}|g" \
           -e "s|@BUILD_URL@|${BUILD_URL}|g" -e "s|@DATE@|${BUILD_DATE}|g" release-notes.tex \
 && pdflatex -interaction=nonstopmode -halt-on-error release-notes.tex >/dev/null \
 && pdflatex -interaction=nonstopmode -halt-on-error release-notes.tex | tail -2

FROM scratch AS out
COPY --from=tex /doc/release-notes.pdf /doc/classes_pricing.png /doc/packages_pricing.png /
