.PHONY: help test coverage crap gui gui-smoke cli cli-ai cli-all-ai clean

# Help
# Show available make targets
help:
	@echo "Available targets:"
	@echo "  help        - Show this help"
	@echo "  .venv       - Bootstrap virtual environment with PySide6 and pytest"
	@echo "  test        - Run the test suite"
	@echo "  coverage    - Run tests with coverage report"
	@echo "  crap        - Run CRAP index report (code ranking by accessibility and risk/potential)"
	@echo "  gui         - Launch the Othello Qt GUI"
	@echo "  gui-smoke   - Run offscreen GUI smoke test"
	@echo "  cli         - Play Othello in the terminal (human vs AI)"
	@echo "  cli-ai      - Play Othello in the terminal (human vs AI, explicit)"
	@echo "  cli-all-ai  - Both players AI, auto-plays to completion"
	@echo "  clean       - Remove the virtual environment"

VENV = .venv

$(VENV)/bin/activate:
	python3 -m venv $(VENV)
	$(VENV)/bin/pip install PySide6 pytest pytest-cov radon

.venv: $(VENV)/bin/activate

# Test
# Run the test suite
test: $(VENV)/bin/activate
	. $(VENV)/bin/activate && python -m pytest tests/ -v

# Coverage
# Run tests with coverage report (produces coverage.json for crap target)
coverage: $(VENV)/bin/activate
	. $(VENV)/bin/activate && python -m pytest tests/ --cov=. --cov-report=term-missing --cov-report=html:coverage_html --cov-report=json -v

# CRAP
# CRAP scores per function (complexity * untested), sorted worst first.
# Requires coverage.json — run 'make coverage' first.
crap: $(VENV)/bin/activate
	@if [ ! -f coverage.json ]; then \
	  echo "No coverage.json — run 'make coverage' first" >&2; exit 1; \
	fi
	. $(VENV)/bin/activate && python scripts/crap.py .

# GUI
# Launch the Othello Qt GUI
gui: $(VENV)/bin/activate
	. $(VENV)/bin/activate && python qt_othello.py

# CLI
# Play Othello in the terminal (human vs AI — default mode)
cli: $(VENV)/bin/activate
	. $(VENV)/bin/activate && python othello.py

# CLI AI
# Play Othello in the terminal (human vs AI, explicit)
cli-ai: $(VENV)/bin/activate
	. $(VENV)/bin/activate && python othello.py -w

# CLI ALL-AI
# Both players AI, auto-plays to completion
cli-all-ai: $(VENV)/bin/activate
	. $(VENV)/bin/activate && python othello.py --all-ai --no-hints

# Clean
# Remove the virtual environment
clean:
	rm -rf $(VENV)

# GUI Smoke Test
# Run offscreen GUI smoke test
gui-smoke: $(VENV)/bin/activate
	. $(VENV)/bin/activate && QT_QPA_PLATFORM=offscreen python -m pytest tests/test_gui_smoke.py -v

