SHELL := /bin/sh

ENV_FILE ?= .env.local
FEATURES ?= --all-features
EXAMPLE ?= send_transactional_email
PACKAGE ?= sendpulse

.PHONY: help fmt check lint test examples doc package publish-dry-run dev-check dev-test dev-example live-test clean

help:
	@printf '%s\n' \
		'make fmt                         Run rustfmt check' \
		'make check                       Run cargo check with FEATURES, default --all-features' \
		'make lint                        Run clippy with -D warnings' \
		'make test                        Run cargo test with FEATURES' \
		'make examples                    Compile all examples' \
		'make doc                         Build rustdoc' \
		'make package                     Run cargo package --allow-dirty' \
		'make publish-dry-run             Run cargo publish --dry-run --allow-dirty' \
		'make dev-check                   Load ENV_FILE, then run cargo check' \
		'make dev-test                    Load ENV_FILE, then run cargo test' \
		'make dev-example EXAMPLE=name    Run an example after loading ENV_FILE, default .env.local' \
		'make live-test                   Run tests with live-tests feature after loading ENV_FILE' \
		'make clean                       Clean target directory'

fmt:
	cargo fmt --check

check:
	cargo check $(FEATURES)

lint:
	cargo clippy --workspace $(FEATURES) -- -D warnings

test:
	cargo test --workspace $(FEATURES)

examples:
	cargo check --examples --all-features

doc:
	cargo doc --workspace --all-features --no-deps

package:
	cargo package --allow-dirty

publish-dry-run:
	cargo publish --dry-run --allow-dirty

dev-check:
	set -a; [ ! -f "$(ENV_FILE)" ] || . "$(ENV_FILE)"; set +a; cargo check $(FEATURES)

dev-test:
	set -a; [ ! -f "$(ENV_FILE)" ] || . "$(ENV_FILE)"; set +a; cargo test --workspace $(FEATURES)

dev-example:
	set -a; [ ! -f "$(ENV_FILE)" ] || . "$(ENV_FILE)"; set +a; cargo run --example "$(EXAMPLE)" --all-features

live-test:
	set -a; [ ! -f "$(ENV_FILE)" ] || . "$(ENV_FILE)"; set +a; SENDPULSE_LIVE_TESTS=1 cargo test --workspace --features live-tests

clean:
	cargo clean
