.PHONY: help venv install install-test install-global lint test test-unit test-integration build clean

VENV := .venv
PYTHON := $(VENV)/bin/python
PIP := $(VENV)/bin/pip

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

venv: ## Create virtual environment
	python3 -m venv $(VENV)

install: ## Install package in editable mode
	$(PIP) install -e .

install-test: ## Install with test dependencies
	$(PIP) install -e ".[test]"

lint: ## Run ruff linter
	$(PYTHON) -m ruff check mcp_email_index tests

test: ## Run all tests (excluding integration)
	$(PYTHON) -m pytest tests/ -m "not integration" -v

test-unit: test ## Alias for test

test-integration: ## Run integration tests (requires Docker)
	$(PYTHON) -m pytest tests/ -m integration -v

install-global: build ## Install wheel globally (breaks system packages)
	pip3 install --force-reinstall --no-deps --break-system-packages dist/mcp_email_index-*.whl

build: clean ## Build wheel and sdist
	$(PIP) install build
	$(PYTHON) -m build

clean: ## Remove build artifacts and caches
	rm -rf dist/ build/ *.egg-info
	rm -rf .pytest_cache .hypothesis .coverage
	find . -type d -name __pycache__ -exec rm -rf {} +
