FROM python:3.12-slim

# Dipendenze di sistema
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    libpq-dev \
    curl \
    tesseract-ocr \
    tesseract-ocr-ita \
    tesseract-ocr-eng \
    poppler-utils \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /worker

# Installa dipendenze Python
COPY pyproject.toml .
RUN pip install --no-cache-dir -e ".[dev]"

# Copia codice sorgente
COPY . .

# Healthcheck: verifica che il processo worker sia vivo
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
    CMD python -c "import redis; r = redis.Redis.from_url('${REDIS_URL:-redis://redis:6379/0}'); r.ping()" || exit 1

# Entrypoint: avvia il worker arq
CMD ["python", "-m", "app.main"]
