ROOT_DIR := $(shell pwd)
PYTHON ?= python3

.PHONY: help install uninstall sync-skill

help:
	@echo "Usage: make [target]"
	@echo ""
	@echo "  install     Install mytoolkit in editable mode (current Python) and sync skill"
	@echo "  sync-skill  Copy the bundled Claude skill to ~/.claude/skills/mytoolkit/"
	@echo "  uninstall   Uninstall mytoolkit and remove shell completions"

install:
	$(PYTHON) -m pip install -e "$(ROOT_DIR)" --upgrade
	@echo "Installing shell completions…"
	@mytoolkit completion install || echo "Warning: completion install failed"
	@$(MAKE) -s sync-skill

sync-skill:
	@echo "Syncing Claude skill to ~/.claude/skills/mytoolkit/ ..."
	@mkdir -p "$(HOME)/.claude/skills"
	@if command -v rsync >/dev/null 2>&1; then \
		rsync -av --delete "$(ROOT_DIR)/.claude/skills/mytoolkit/" "$(HOME)/.claude/skills/mytoolkit/"; \
	else \
		rm -rf "$(HOME)/.claude/skills/mytoolkit"; \
		cp -R "$(ROOT_DIR)/.claude/skills/mytoolkit" "$(HOME)/.claude/skills/mytoolkit"; \
	fi

uninstall:
	@mytoolkit uninstall || $(PYTHON) -m pip uninstall mytoolkit -y
