.DEFAULT_GOAL := help

.PHONY: help deps test test-cov lint format format-check typing docs package cypher-audit manual-check manual-update manual-diff manual-dump manual-audit manual-report matrix

help:  ## Show the available targets.
	@awk 'BEGIN {FS = ":.*## "; printf "Targets:\n"} /^[a-z-]+:.*## / {printf "  %-14s %s\n", $$1, $$2}' $(MAKEFILE_LIST)

deps:  ## Install the locked development and test groups.
	uv sync --group dev --group test

test:  ## Run the unit suite on the current interpreter.
	uv run --group test pytest

test-cov:  ## Run the unit suite on the current interpreter and report coverage.
	uv run --group test pytest --cov=cypher_dsl --cov-report=term-missing

lint:  ## Check the source with Ruff.
	uv run ruff check .

format:  ## Format the source with Ruff.
	uv run ruff format .

format-check:  ## Check formatting without writing.
	uv run ruff format --check .

typing:  ## Run mypy in strict mode.
	uv run mypy

docs:  ## Build the documentation without network access.
	uv run nox -s docs

package:  ## Build an sdist and wheel, then smoke the installed wheel.
	uv run nox -s package

cypher-audit:  ## Audit rendered Cypher in a disposable Neo4j Enterprise container.
	uv run --group audit python -m tools.check_cypher


manual-check:  ## Compare the committed examples with the recorded upstream commit.
	uv run python -m tools.manual_examples check

manual-update:  ## Write a review candidate from the upstream head. Optional CANDIDATE=DIR.
	uv run python -m tools.manual_examples update $(if $(CANDIDATE),--candidate "$(CANDIDATE)")

manual-diff:  ## Report how a review candidate differs. Requires CANDIDATE=DIR.
	@test -n "$(CANDIDATE)" || { echo "Set CANDIDATE=DIR."; exit 1; }
	uv run python -m tools.manual_examples diff "$(CANDIDATE)"

manual-dump:  ## Write a fresh unreviewed extraction. Requires DEST=DIR, optional COMMIT=SHA.
	@test -n "$(DEST)" || { echo "Set DEST=DIR."; exit 1; }
	uv run python -m tools.manual_examples dump "$(DEST)" $(if $(COMMIT),--commit "$(COMMIT)")

manual-audit:  ## Send every stored example text to Neo4j and report the rejections. Optional STATUS=name.
	uv run --group audit python -m tools.manual_examples audit $(if $(STATUS),--status "$(STATUS)")

manual-report:  ## Print the status totals, or the entries of a status. Optional STATUS=name, VERBOSE=1.
	uv run python -m tools.manual_examples report $(if $(VERBOSE),--verbose) $(if $(STATUS),--status "$(STATUS)")

matrix:  ## Run every unique Nox job once through the aggregate session.
	uv run nox -s matrix
