FROM python:3.12-slim

WORKDIR /app

# Install system dependencies including Playwright requirements
RUN apt-get update && apt-get install -y \
    gcc \
    postgresql-client \
    wget \
    && rm -rf /var/lib/apt/lists/*

# Copy dependency specification first for better layer caching
COPY pyproject.toml ./

# Copy application packages (needed before pip install)
COPY packages/ ./packages/
COPY apps/ ./apps/
COPY infrastructure/alembic/ ./infrastructure/alembic/
COPY infrastructure/alembic.ini ./infrastructure/
COPY infrastructure/scripts/ ./infrastructure/scripts/

# Install Python dependencies (including dev/test dependencies)
RUN pip install --no-cache-dir ".[dev]"

# Install Playwright browsers (Chromium only for web scraping)
RUN playwright install --with-deps chromium

# Create necessary directories
RUN mkdir -p /app/reports /app/.cache

# Set PYTHONPATH to ensure modules are found
ENV PYTHONPATH=/app:$PYTHONPATH

# Default command (can be overridden)
CMD ["python", "-m", "apps.backend.worker.cli", "--help"]
