LANG=en_US.utf-8

export LANG

# Bridge the org-standard JFrog vars to what native uv expects (index name: jfrog).
# Username is optional — a bare token authenticates against the virtual-pypi index.
UV_INDEX_JFROG_USERNAME ?= $(JFROG_READ_USER)
UV_INDEX_JFROG_PASSWORD ?= $(JFROG_READ_TOKEN)
export UV_INDEX_JFROG_USERNAME
export UV_INDEX_JFROG_PASSWORD

.PHONY: sync
sync: ## Create/update the local .venv (deps + dev group)
	uv sync --group dev
	@echo "✅ .venv synced. Point your IDE interpreter at ./.venv"

.PHONY: lock
lock: ## Regenerate uv.lock from pyproject.toml
	uv lock
	@echo "✅ uv.lock updated"

.PHONY: init
init: sync setup-pre-commit ## Initialize the local developer environment

.PHONY: tests
tests: ## Run the unit test suite (excludes integration) with coverage
	uv run pytest -m "not integration" tests helix_personmatching --cov --cov-report=term-missing

.PHONY: tests-all
tests-all: ## Run the full test suite, including integration tests, with coverage
	uv run pytest tests helix_personmatching --cov --cov-report=term-missing

.PHONY: fmt
fmt: ## Format, lint (auto-fix), and typecheck
	uv run ruff format helix_personmatching tests
	uv run ruff check --fix helix_personmatching tests
	uv run mypy helix_personmatching tests

.PHONY: fmt-ci
fmt-ci: ## CI lint gate: format check, lint, typecheck (no auto-fix)
	uv run ruff format --check helix_personmatching tests
	uv run ruff check helix_personmatching tests
	uv run mypy --strict --explicit-package-bases helix_personmatching tests

.PHONY: setup-pre-commit
setup-pre-commit: ## Install the pre-commit git hook (uv-managed, no Docker)
	uv run pre-commit install

.PHONY: run-pre-commit
run-pre-commit: ## Run all pre-commit hooks over all files (no install needed)
	uv run pre-commit run --all-files

.PHONY: clean-pre-commit
clean-pre-commit: ## Uninstall the pre-commit git hook
	uv run pre-commit uninstall

.PHONY: build
build: ## Build the sdist + wheel into dist/
	rm -rf dist/
	uv build

.PHONY: testpackage
testpackage: build ## Upload the built distribution to TestPyPI (token in TWINE_PASSWORD)
	uv run twine upload -u __token__ --repository testpypi dist/*

.PHONY: package
package: build ## Upload the built distribution to PyPI (token in TWINE_PASSWORD)
	uv run twine upload -u __token__ --repository pypi dist/*

.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help.
	# from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'