.DEFAULT_GOAL := all

.PHONY: .uv  ## Check that uv is installed
.uv:
	@uv -V || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'

.PHONY: install  ## Install the package and dependencies for local development
install: .uv
	uv sync --frozen --all-extras

.PHONY: sync  ## Sync venv with all dependencies (updates lockfile if needed)
sync: .uv
	uv sync --all-extras

.PHONY: rebuild-lockfile  ## Rebuild lockfile from scratch, updating all dependencies
rebuild-lockfile: .uv
	uv lock --upgrade

.PHONY: test  ## Run all tests (unit + round-trip + integration + compression benchmarks)
test: .uv
	uv run pytest tests/ -q --tb=short --cov=wick_formatter --cov-report=term-missing --ignore=tests/benchmarks/test_accuracy.py

.PHONY: test-unit  ## Run unit tests only
test-unit: .uv
	uv run pytest tests/unit/ -q --tb=short --cov=wick_formatter --cov-report=term-missing

.PHONY: test-round-trip  ## Run round-trip fixture and hypothesis tests
test-round-trip: .uv
	uv run pytest tests/round_trip/ -q --tb=short --cov=wick_formatter --cov-report=term-missing

.PHONY: test-integration  ## Run CLI and MCP integration tests
test-integration: .uv
	uv run pytest tests/integration/ -q --tb=short --cov=wick_formatter --cov-report=term-missing

.PHONY: benchmark  ## Run full benchmark suite including accuracy gate (requires Ollama)
benchmark: .uv
	uv run pytest tests/benchmarks/ --run-benchmarks -q --tb=short -s

.PHONY: benchmark-quick  ## Run benchmark suite in quick mode (5 WTQ + 5 custom, ~2 min)
benchmark-quick: .uv
	uv run pytest tests/benchmarks/ --run-benchmarks --quick -q --tb=short -s

.PHONY: benchmark-compression  ## Run compression gate only (no Ollama needed)
benchmark-compression: .uv
	uv run pytest tests/benchmarks/test_compression.py -q --tb=short

.PHONY: clean  ## Clear local caches and build artifacts
clean:
	rm -rf `find . -name __pycache__`
	rm -f `find . -type f -name '*.py[co]'`
	rm -f `find . -type f -name '*~'`
	rm -rf .cache
	rm -rf .pytest_cache
	rm -rf htmlcov
	rm -rf *.egg-info
	rm -f .coverage
	rm -f .coverage.*
	rm -rf build
	rm -rf dist
	rm -rf target
	rm -rf .venv

.PHONY: all  ## Run the standard pre-commit checks (test + compression benchmark)
all: test benchmark-compression

.PHONY: client-claude  ## Install wick-formatter MCP server for Claude Code
client-claude:
	@./scripts/client-setup.sh install claude

.PHONY: client-codex  ## Install wick-formatter MCP server for Codex
client-codex:
	@./scripts/client-setup.sh install codex

.PHONY: client-status  ## Show MCP client configuration status
client-status:
	@./scripts/client-setup.sh status

.PHONY: client-clean  ## Remove wick-formatter from all MCP clients
client-clean:
	@./scripts/client-setup.sh uninstall

.PHONY: help  ## Display this message
help:
	@grep -E \
		'^.PHONY: .*?## .*$$' $(MAKEFILE_LIST) | \
		sort | \
		awk 'BEGIN {FS = ".PHONY: |## "}; {printf "\033[36m%-22s\033[0m %s\n", $$2, $$3}'

.PHONY: hooks  ## Set up git hooks for local development
hooks:
	git config core.hooksPath .githooks
	@echo "Git hooks configured to use .githooks/"

.PHONY: docker-build  ## Build Docker image locally
docker-build:
	docker build -t wick-formatter:local .

.PHONY: docker-run  ## Run MCP server in Docker (stdio)
docker-run: docker-build
	docker run -i --rm wick-formatter:local
