FROM python:3.13-slim

WORKDIR /app

RUN pip install --no-cache-dir \
    google-cloud-firestore \
    google-cloud-secret-manager \
    google-adk \
    google-genai \
    fastapi \
    uvicorn \
    cryptography \
    pydantic \
    google-cloud-logging \
    httpx \
    "a2a-sdk[fastapi]"

COPY . gateway/recommender/

# Need __init__.py for the gateway package and auditor sub-package
RUN mkdir -p gateway && touch gateway/__init__.py
RUN mkdir -p gateway/auditor && touch gateway/auditor/__init__.py

# Inline the list_tenants function to avoid cross-package COPY issues
RUN echo 'from google.cloud import firestore\n\ndef list_tenants(db: firestore.Client) -> list[str]:\n    return [t.id for t in db.collection("tenants").list_documents()]' \
    > gateway/auditor/receipt_reader.py

ENV PYTHONUNBUFFERED=1
ENV PORT=8080
EXPOSE 8080

CMD exec uvicorn gateway.recommender.recommender_service:app \
    --host 0.0.0.0 --port ${PORT} \
    --workers 1 --timeout-keep-alive 75
