.DEFAULT_GOAL := help
P ?= 100

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

install: ## Install otter globally
	uv tool install -e . --force

uninstall: ## Uninstall otter globally
	uv tool uninstall otter-stream

install-dev: ## Install development dependencies
	uv sync --group dev

lint: ## Run ruff linter
	uv run ruff check .

format: ## Run ruff formatter
	uv run ruff format .

test: ## Run all tests
	uv run pytest tests/ -v

test-unit: ## Run unit tests only
	uv run pytest tests/ --ignore=tests/integration -v

cli-install: ## Install package in editable mode
	uv pip install -e .


release: ## Create a release (e.g. make release V=0.1.0)
	@test -n "$(V)" || (echo "Usage: make release V=x.y.z" && exit 1)
	@git diff --quiet || (echo "Error: working tree is dirty, commit changes first" && exit 1)
	@head -10 CHANGELOG.md | grep -q "## Unreleased" || (echo "Error: no Unreleased section in CHANGELOG.md" && exit 1)
	python3 -c "import pathlib; p = pathlib.Path('CHANGELOG.md'); p.write_text(p.read_text().replace('## Unreleased', '## Unreleased\n\n## v$(V) - $(shell date +%Y-%m-%d)'))"
	git add CHANGELOG.md
	git commit -m "Release v$(V)"
	git tag v$(V)
	@echo "Tagged v$(V). Push with: git push origin main v$(V)"
