# Storage engine playground helpers.

HAS_CARGO := $(wildcard Cargo.toml)

.DEFAULT_GOAL := help

.PHONY: help
help: ## Show help messages for all available targets
	@grep -E '^[a-zA-Z_-]+:.*## .*$$' Makefile | \
	awk 'BEGIN {FS = ":.*## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

.PHONY: fmt
fmt: ## Format Rust code
	@if [ -z "$(HAS_CARGO)" ]; then \
		echo "No Cargo.toml found. Skipping Rust formatting."; \
	else \
		cargo fmt --all; \
	fi

.PHONY: fmt-check
fmt-check: ## Check Rust formatting
	@if [ -z "$(HAS_CARGO)" ]; then \
		echo "No Cargo.toml found. Skipping Rust format check."; \
	else \
		cargo fmt --all --check; \
	fi

.PHONY: clippy
clippy: ## Run Clippy for all targets and features
	@if [ -z "$(HAS_CARGO)" ]; then \
		echo "No Cargo.toml found. Skipping Clippy."; \
	else \
		cargo clippy --all-targets --all-features -- -D warnings; \
	fi

.PHONY: test
test: ## Run Rust tests for all targets and features
	@if [ -z "$(HAS_CARGO)" ]; then \
		echo "No Cargo.toml found. Skipping Rust tests."; \
	else \
		cargo test --all-targets --all-features; \
	fi

.PHONY: check
check: fmt-check clippy test ## Run all Rust checks

.PHONY: clean
clean: ## Remove build output
	@if [ -z "$(HAS_CARGO)" ]; then \
		echo "No Cargo.toml found. Nothing to clean."; \
	else \
		cargo clean; \
	fi

.PHONY: setup-hooks
setup-hooks: ## Install Git hooks with pre-commit
	@pre-commit install --hook-type pre-commit
	@pre-commit install --hook-type pre-push
	@pre-commit install-hooks

.PHONY: test-hooks
test-hooks: ## Run pre-commit hooks across all files
	@pre-commit run --all-files --show-diff-on-failure
