.PHONY: build release test clean install fmt lint check doc

# Default target
all: build

# Build debug version
build:
	cargo build

# Build release version
release:
	cargo build --release

# Run tests
test:
	cargo test

# Run integration tests
test-integration:
	cargo test --test integration_tests

# Clean build artifacts
clean:
	cargo clean

# Install locally (requires cargo-install)
install:
	cargo install --path .

# Format code
fmt:
	cargo fmt

# Check formatting
check-fmt:
	cargo fmt -- --check

# Run clippy linter
lint:
	cargo clippy -- -D warnings

# Run all checks
check: check-fmt lint test

# Generate documentation
doc:
	cargo doc --no-deps --open

# Run with debug logging
debug:
	RUST_LOG=debug cargo run -- $(ARGS)

# Build and run
run: build
	./target/debug/quicommit $(ARGS)

# Build release and run
run-release: release
	./target/release/quicommit $(ARGS)

# Generate shell completions
completions: release
	mkdir -p completions
	./target/release/quicommit completions bash > completions/quicommit.bash
	./target/release/quicommit completions zsh > completions/_quicommit
	./target/release/quicommit completions fish > completions/quicommit.fish
	./target/release/quicommit completions powershell > completions/_quicommit.ps1

# Development helpers
dev-setup:
	rustup component add rustfmt clippy

# CI pipeline
ci: check-fmt lint test
	@echo "All CI checks passed!"

# Help
help:
	@echo "Available targets:"
	@echo "  build          - Build debug version"
	@echo "  release        - Build release version"
	@echo "  test           - Run all tests"
	@echo "  clean          - Clean build artifacts"
	@echo "  install        - Install locally"
	@echo "  fmt            - Format code"
	@echo "  lint           - Run clippy linter"
	@echo "  check          - Run all checks (fmt, lint, test)"
	@echo "  doc            - Generate documentation"
	@echo "  run            - Build and run (use ARGS='...' for arguments)"
	@echo "  completions    - Generate shell completions"
	@echo "  ci             - Run CI pipeline"
