.PHONY: test image image-export deploy-rsync help

UV ?= $(shell command -v uv 2>/dev/null || echo uv)
IMAGE ?= rein-aharness:railiance01
TAR ?= /tmp/rein-aharness-railiance01.tar

help: ## Show targets
	@grep -Eh '^[a-zA-Z_-]+:.*?##' $(MAKEFILE_LIST) | \
	  awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-16s\033[0m %s\n", $$1, $$2}'

test: ## Run unit tests
	PYTHONPATH=".:$$HOME/llm-connect" python3 -m pytest tests/ -q

image: ## Build container image (vendors ../llm-connect when present)
	rm -rf llm_connect_vendor
	mkdir -p llm_connect_vendor
	if [ -d ../llm-connect/llm_connect ]; then \
	  cp -a ../llm-connect/llm_connect ../llm-connect/pyproject.toml ../llm-connect/README.md llm_connect_vendor/ 2>/dev/null || \
	  cp -a ../llm-connect/llm_connect ../llm-connect/pyproject.toml llm_connect_vendor/; \
	  touch llm_connect_vendor/README.md; \
	fi
	docker build -f Containerfile -t $(IMAGE) .
	rm -rf llm_connect_vendor

image-export: image ## Save image tar for k3s import
	docker save -o $(TAR) $(IMAGE)
	@ls -lh $(TAR)

deploy-rsync: ## Rsync tree to railiance01:~/rein-aharness
	rsync -az --delete \
	  --exclude '.git' --exclude '.venv' --exclude '__pycache__' --exclude '.pytest_cache' \
	  --exclude 'llm_connect_vendor' --exclude '*.egg-info' \
	  ./ railiance01:rein-aharness/
