ARG PYTHON_VERSION=3.13

# ---------------------------------------------------------------------------
# Base — Python + uv
# ---------------------------------------------------------------------------
FROM python:${PYTHON_VERSION}-slim AS base

COPY --from=ghcr.io/astral-sh/uv:0.8.13 /uv /uvx /bin/

ENV UV_LINK_MODE=copy \
    UV_NO_SYNC=1 \
    UV_PROJECT_ENVIRONMENT=/var/venv \
    VIRTUAL_ENV=/var/venv \
    PATH="/var/venv/bin:$PATH"

WORKDIR /app

# ---------------------------------------------------------------------------
# deps — install dependencies (no source, for layer caching)
# ---------------------------------------------------------------------------
FROM base AS deps

COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-default-groups --no-install-project

# ---------------------------------------------------------------------------
# source — copy project files
# ---------------------------------------------------------------------------
FROM deps AS source

COPY src/ src/
COPY tests/ tests/
COPY templates/ templates/
COPY config.shadow.json ./

# ---------------------------------------------------------------------------
# venv-dev — dev + test dependencies
# ---------------------------------------------------------------------------
FROM source AS venv-dev

RUN uv sync --frozen --group dev

# ---------------------------------------------------------------------------
# venv-integration — dev + integration dependencies
# ---------------------------------------------------------------------------
FROM source AS venv-integration

RUN uv sync --frozen --group integration

# ---------------------------------------------------------------------------
# unit-lint — run linting and unit tests
# ---------------------------------------------------------------------------
FROM venv-dev AS unit-lint

CMD ["sh", "-c", "ruff check && ruff format --check && pytest tests/unit -v"]

# ---------------------------------------------------------------------------
# test-integration — run integration tests
# ---------------------------------------------------------------------------
FROM venv-integration AS test-integration

CMD ["pytest", "tests/integration", "-v"]
