# Polleo Demand — FastAPI backend.
# Python 3.12 is the supported target (NOT 3.14 — no scipy/statsforecast wheels).
FROM python:3.12-slim

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1

WORKDIR /app

# libgomp1 = OpenMP runtime needed by scipy/scikit-learn/statsforecast.
# curl = container healthcheck. No compilers needed: all heavy deps ship wheels.
RUN apt-get update \
    && apt-get install -y --no-install-recommends libgomp1 curl \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN pip install --upgrade pip && pip install -r requirements.txt

COPY backend/ backend/
COPY db/ db/
COPY forecast_v4/ forecast_v4/
# forecast_db.py: self-contained DB helper for the Demand Plan Excel round-trip
# (download-plan / upload-plan). Recomputes total = baseline*factor + on-tops.
COPY forecast_db.py forecast_db.py

# data/ is provided at runtime via a bind mount (config + persisted CSV writes).
EXPOSE 8000

# Single worker: the app holds in-process state (forecast run) — don't scale workers.
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "8000"]
