.PHONY: help sync migrate run test lint shell check test-usecases test-browser setup-usecases check-communication check-owner-communication check-native-recovery

.DEFAULT_GOAL := help

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

sync: ## Install Python deps with uv
	uv sync

migrate: ## Apply migrations
	uv run manage.py migrate

run: ## Dev server on :8008
	uv run manage.py runserver 0.0.0.0:8008

test: ## pytest
	uv run pytest

lint: ## ruff
	uv run ruff check .

shell: ## Django shell
	uv run manage.py shell

setup-usecases: ## Install locked Node deps and Chromium for use-case checks
	npm ci --prefix scripts
	cd scripts && npx playwright install chromium

test-usecases: ## Required established journeys (fast + real browser), JUnit report
	uv run pytest --verify-usecases -m usecase --junitxml=var/test-results/usecases.xml

test-browser: ## Browser journeys against isolated test app
	uv run pytest --verify-usecases -m browser --junitxml=var/test-results/browser.xml

check: lint ## Full lint/regression gate, including every established browser journey
	uv run pytest --verify-usecases -m '' --junitxml=var/test-results/check.xml

check-communication: ## Send-free owner retry/privacy checks; set EMAIL_CONNECT_ROOT
	uv run python scripts/check-communication.py --owner "$(EMAIL_CONNECT_ROOT)"

check-owner-communication: ## Real owner-source browser journey; set both owner roots and a fresh OWNER_BROWSER_RECEIPT
	uv run python scripts/check-owner-communication.py --user-engine "$(USER_ENGINE_ROOT)" --email-connect "$(EMAIL_CONNECT_ROOT)" --receipt "$(OWNER_BROWSER_RECEIPT)"

check-native-recovery: ## Native isolated reset/SMTP/directory/issuer/app browser; set a fresh NATIVE_BROWSER_RECEIPT
	uv run python scripts/check-native-recovery.py --receipt "$(NATIVE_BROWSER_RECEIPT)"
