# Makefile for StemeDB

.PHONY: all build dev quality install clean test help

# Default target
all: build

## --- Development ---

# Build the project (dev profile)
build:
	cargo build

# Run the project
dev:
	cargo run -p stemedb-core

# Run tests
test:
	cargo test --workspace

## --- Quality & Verification ---

# Run all quality checks (formatting, linting, duplication, tests)
quality: fmt-check lint duplication test
	@echo "✅ Quality checks passed!"

# Check for code duplication
duplication:
	@echo "Checking for code duplication..."
	@jscpd ./crates --format rust --min-lines 5 --min-tokens 50 || true

# Check formatting without changing files
fmt-check:
	cargo fmt --all -- --check

# Run clippy (linter)
lint:
	cargo clippy --workspace --all-targets --all-features -- -D warnings

# Fix formatting automatically
fmt:
	cargo fmt --all

## --- Installation ---

# Install dependencies (Rust toolchain, etc - assumed cargo exists)
install:
	@echo "Ensuring rust toolchain is up to date..."
	rustup update stable
	@echo "Installing helpful tools..."
	# cargo install cargo-watch # Optional but recommended

## --- Utilities ---

clean:
	cargo clean

help:
	@echo "Available commands:"
	@echo "  make build       - Build the workspace"
	@echo "  make dev         - Run the core binary"
	@echo "  make test        - Run unit tests"
	@echo "  make quality     - Run format check, clippy, duplication, tests"
	@echo "  make fmt         - Auto-format code"
	@echo "  make lint        - Run clippy linter"
	@echo "  make duplication - Check for code duplication (jscpd)"
	@echo "  make install     - Setup environment"
