.PHONY: install test lint publish-github

install:
	uv sync

test:
	uv run pytest -q

lint:
	uv run ruff check src tests

# Publish this subdirectory to a fresh GitHub repo with full history.
#
# Usage:
#   make publish-github REPO=git@github.com:advantch/vanty-mail.git [BRANCH=main]
#
# Requires `git-filter-repo` to be installed (see https://github.com/newren/git-filter-repo).
# Safe note: this clones the parent monorepo into a temp directory and runs
# `git filter-repo --subdirectory-filter vanty-mail --force` on that copy
# only. Your working monorepo is never touched.
publish-github:
	@if [ -z "$(REPO)" ]; then \
		echo "REPO is required. Example: make publish-github REPO=git@github.com:advantch/vanty-mail.git"; \
		exit 1; \
	fi
	@command -v git-filter-repo >/dev/null 2>&1 || { \
		echo "git-filter-repo is required. Install with: pip install git-filter-repo"; \
		exit 1; \
	}
	@BRANCH=$${BRANCH:-main}; \
	MONOREPO_ROOT="$$(git -C $(CURDIR) rev-parse --show-toplevel)"; \
	TMPDIR="$$(mktemp -d -t vanty-mail-publish-XXXXXX)"; \
	echo "Cloning monorepo from $$MONOREPO_ROOT into $$TMPDIR ..."; \
	git clone --no-local "$$MONOREPO_ROOT" "$$TMPDIR/vanty-mail-export"; \
	cd "$$TMPDIR/vanty-mail-export" && \
		git filter-repo --subdirectory-filter vanty-mail --force && \
		git remote add origin "$(REPO)" && \
		git branch -M "$$BRANCH" && \
		git push -u origin "$$BRANCH"; \
	echo "Published vanty-mail to $(REPO) (branch $$BRANCH). Temp dir: $$TMPDIR"
