FROM python:3.12-slim

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        build-essential \
        libgl1 \
        libglib2.0-0 \
        git \
        # V1 pipeline: LibreOffice for office-to-PDF conversion
        libreoffice \
        default-jre \
        libreoffice-java-common && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install reflow from PyPI with ML deps (V2 pipeline)
RUN pip install --no-cache-dir "pyreflow[ml]>=0.1.0"

# Copy handbook generator
COPY . /app/

# Install remaining server deps (shared + V1 + V2)
RUN pip install --no-cache-dir \
    "fastapi>=0.100.0" \
    "uvicorn[standard]>=0.24.0" \
    "redis>=5.0.0" \
    "google-cloud-storage>=2.13.0" \
    "httpx>=0.25.0" \
    "python-dotenv>=1.0.0" \
    "beautifulsoup4>=4.12.0" \
    "openai>=1.3.5" \
    "pypdfium2>=4.24.0" \
    "Pillow>=10.1.0" \
    "pymupdf>=1.26.0" \
    "pypdf2>=3.0.1" \
    "pdfplumber>=0.11.6" \
    "google-auth>=2.23.4" \
    "google-api-core>=2.14.0" \
    "requests>=2.31.0"

EXPOSE 8080

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
