FROM python:3.12-slim

# GDAL and geo dependencies for GeoDjango
RUN apt-get update && apt-get install -y --no-install-recommends \
    gdal-bin \
    libgdal-dev \
    libgeos-dev \
    libproj-dev \
    binutils \
    libgl1 \
    && rm -rf /var/lib/apt/lists/*

# X11/OpenGL runtime libs required by OCP (OpenCASCADE Python bindings used by build123d)
RUN apt-get update && apt-get install -y --no-install-recommends \
    libxrender1 \
    libxi6 \
    libxext6 \
    libx11-6 \
    && rm -rf /var/lib/apt/lists/*

ENV GDAL_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/libgdal.so
ENV GEOS_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/libgeos_c.so

WORKDIR /app

ARG REQUIREMENTS=base
COPY requirements/ requirements/
RUN pip install --no-cache-dir -r requirements/${REQUIREMENTS}.txt

COPY . .

RUN python manage.py collectstatic --noinput 2>/dev/null || true

EXPOSE 8000

CMD ["gunicorn", "config.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "4"]
