.PHONY: up down logs test lint seed reset n8n-setup n8n-setup-scan demo e2e

up:
	docker compose up --build -d

down:
	docker compose down

logs:
	docker compose logs -f --tail=200

test:
	sh scripts/run-isolated-tests.sh

lint:
	docker compose run --rm api ruff check .
	docker compose run --rm api mypy app

seed:
	docker compose exec api python -m app.cli seed --reset

reset:
	docker compose down -v
	docker compose up --build -d

# One-time per environment: imports and activates the n8n return-processing workflow.
# The n8n owner account itself cannot be scripted safely and must be created once at
# http://localhost:5678/setup (any email/password, no verification required) before
# this target's activation takes effect. The workflow also needs the "Fleet Ops Webhook
# Trigger Token" and "Fleet Ops Service Token" Header Auth credentials created manually in
# the n8n UI before it will actually process a return -- see docs/17-runbook.md.
n8n-setup:
	docker compose exec n8n n8n import:workflow --input=//imports/workflows/fleet-ops-vehicle-return.json
	docker compose exec n8n n8n publish:workflow --id=mobilityops-return-processing
	docker compose restart n8n

# One-time per environment: imports and activates the scheduled quality-scan workflow.
# Same owner-account and credential preconditions as n8n-setup above (this workflow only
# needs "Fleet Ops Service Token").
n8n-setup-scan:
	docker compose exec n8n n8n import:workflow --input=//imports/workflows/fleet-ops-data-quality-scan.json
	docker compose exec n8n n8n publish:workflow --id=mobilityops-scheduled-quality-scan
	docker compose restart n8n

# Full deterministic demo bootstrap: build, migrate (automatic on api startup), seed.
demo: up
	docker compose exec api python -m app.cli seed --reset

e2e:
	cd frontend && npx playwright test
