FROM python:3.12-slim

RUN apt-get update && apt-get install -qyy --no-install-recommends \
    xvfb \
    ffmpeg \
    x11-xserver-utils \
    x11-utils \
    xterm \
    openbox \
    xdotool \
    xfonts-base \
    fonts-jetbrains-mono \
    fonts-dejavu-core \
    && rm -rf /var/lib/apt/lists/*

ENV PYTHONUNBUFFERED=1
ENV TERM=xterm-256color

WORKDIR /app

# Thea recorder (>= 0.19.2: auto WM + focus verification probe)
RUN pip install --no-cache-dir 'thea-recorder>=0.19.2'

# dm CLI dependencies
RUN pip install --no-cache-dir rich pyyaml qrcode

# API Lambda dependencies (auth layer: JWT, TOTP)
RUN pip install --no-cache-dir boto3 PyJWT pyotp python-ulid

# dm CLI
COPY scripts/dm /usr/local/bin/dm
RUN chmod +x /usr/local/bin/dm

# API Lambda code (importable as lambda_api.handler / lambda_api.auth)
COPY lambda/api/handler.py lambda_api/handler.py
COPY lambda/api/auth.py lambda_api/auth.py
RUN touch lambda_api/__init__.py

# Test infrastructure
COPY tests/ tests/

ENTRYPOINT ["python", "-m", "tests.runner"]
