FROM python:3.11-slim AS core

RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential \
        cmake \
        ninja-build \
        git \
        libeigen3-dev \
        libgtest-dev \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /hoptimal
COPY . .

RUN cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DHOPTIMAL_BUILD_TESTS=ON \
 && cmake --build build -j"$(nproc)" \
 && ctest --test-dir build --output-on-failure

RUN pip install --no-cache-dir . && pip install --no-cache-dir pytest

RUN python -c "import hoptimal; \
s=hoptimal.create_study('minimize'); \
s.optimize(lambda t:(t.suggest_float('x',-5,5)-2)**2, 30); \
print('core OK — best:', s.best_value, s.best_params)"

FROM core AS integrations

RUN pip install --no-cache-dir \
        scikit-learn \
        xgboost \
        lightgbm \
        catboost \
        optuna \
        scikit-optimize

RUN python examples/test_sklearn.py \
 && python examples/test_xgboost.py \
 && python examples/test_lightgbm.py \
 && python examples/test_catboost.py

FROM integrations AS dl

RUN pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu
RUN pip install --no-cache-dir "jax[cpu]" flax tensorflow-cpu

RUN python examples/test_pytorch.py \
 && python examples/test_jax.py \
 && python examples/test_tensorflow.py
