.PHONY: help install dev-install test test-verbose test-coverage clean format lint type-check build publish benchmark pre-commit-install pre-commit-run pre-commit-update all

# Default target
help:
	@echo "Available commands:"
	@echo "  make install            - Install package in development mode"
	@echo "  make dev-install        - Install package with development dependencies"
	@echo "  make test               - Run tests"
	@echo "  make test-verbose       - Run tests with verbose output"
	@echo "  make test-coverage      - Run tests with coverage report"
	@echo "  make format             - Format code with ruff"
	@echo "  make lint               - Lint code with ruff"
	@echo "  make type-check         - Run type checking with mypy"
	@echo "  make check              - Run all checks (format, lint, type-check, test)"
	@echo "  make pre-commit-install - Install pre-commit hooks"
	@echo "  make pre-commit-run     - Run pre-commit on all files"
	@echo "  make pre-commit-update  - Update pre-commit hooks"
	@echo "  make build              - Build distribution packages"
	@echo "  make publish            - Publish package to PyPI"
	@echo "  make benchmark          - Run performance benchmarks"
	@echo "  make clean              - Remove build artifacts and cache files"
	@echo "  make all                - Run format, lint, type-check, and test"

# Install package in development mode
install:
	uv pip install -e .

# Install with development dependencies
dev-install:
	uv pip install -e . --all-groups

# Run tests
test:
	pytest tests/

# Run tests with verbose output
test-verbose:
	pytest tests/ -v

# Run tests with coverage
test-coverage:
	pytest tests/ --cov=pyperly --cov-report=html --cov-report=term

# Format code with ruff
format:
	ruff format src/ tests/
	ruff check --fix src/ tests/

# Lint code with ruff
lint:
	ruff check src/ tests/

# Type checking with mypy
type-check:
	mypy src/pyperly

# Run all checks
check: format lint type-check test

# Build distribution packages
build: clean
	uv build

# Publish to PyPI (requires credentials)
publish: build
	uv publish

# Run benchmarks
benchmark:
	python benchmark.py

# Install pre-commit hooks
pre-commit-install:
	pre-commit install

# Run pre-commit on all files
pre-commit-run:
	pre-commit run --all-files

# Update pre-commit hooks to latest versions
pre-commit-update:
	pre-commit autoupdate

# Clean build artifacts and cache
clean:
	rm -rf build/
	rm -rf dist/
	rm -rf *.egg-info
	rm -rf .pytest_cache/
	rm -rf .coverage
	rm -rf htmlcov/
	rm -rf .mypy_cache/
	rm -rf .ruff_cache/
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name "*.pyc" -delete
	find . -type f -name "*.pyo" -delete
	find . -type f -name "*~" -delete

# Run everything
all: format lint type-check test
	@echo "✅ All checks passed!"
