FROM python:3.11-slim

LABEL maintainer="Alexei Dolgolyov <dolgolyov.alexei@gmail.com>"
LABEL description="WLED Screen Controller - Ambient lighting based on screen content"

WORKDIR /app

# Install system dependencies for screen capture
RUN apt-get update && apt-get install -y \
    libxcb1 \
    libxcb-randr0 \
    libxcb-shm0 \
    libxcb-xfixes0 \
    libxcb-shape0 \
    && rm -rf /var/lib/apt/lists/*

# Copy project files and install Python dependencies
COPY pyproject.toml .
COPY src/ ./src/
COPY config/ ./config/
RUN pip install --no-cache-dir ".[notifications]"

# Create directories for data and logs
RUN mkdir -p /app/data /app/logs

# Expose API port
EXPOSE 8080

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD python -c "import httpx; httpx.get('http://localhost:8080/health', timeout=5.0)" || exit 1

# Set Python path
ENV PYTHONPATH=/app/src

# Run the application
CMD ["uvicorn", "wled_controller.main:app", "--host", "0.0.0.0", "--port", "8080"]
