.PHONY: lint test build docs deploy validate clean setup help

PROJECT := tomo

# --- Code quality ---

lint:           ## Lint + format check
	.venv/bin/ruff format src/ tests/
	.venv/bin/ruff check --fix src/ tests/

test: lint      ## Run unit tests with coverage
	.venv/bin/pytest tests/ -v --cov=src/tomo --cov-fail-under=70 -m "not integration"

test-integration: ## Run integration tests (requires PostgreSQL)
	.venv/bin/pytest tests/ -v -m integration

test-all:       ## Run all tests
	.venv/bin/pytest tests/ -v --cov=src/tomo

# --- Build ---

build: test     ## Build wheel + sdist
	rm -rf dist/
	.venv/bin/python -m build
	@echo "Built: $$(ls dist/*.whl 2>/dev/null)"

docs:           ## Build documentation site
	.venv/bin/mkdocs build --strict

# --- Deploy ---

deploy: build   ## Deploy docs to droplet
	cd ~/ops/ansible && ansible-playbook playbooks/deploy-apps.yml --diff -e app_filter=$(PROJECT)

validate:       ## Post-deploy health check
	@curl -sf "https://tomo.rizlabs.com/" > /dev/null && echo "OK: tomo.rizlabs.com"

# --- Maintenance ---

clean:          ## Remove build artifacts
	rm -rf dist/ build/ site/ .pytest_cache .ruff_cache .coverage htmlcov src/*.egg-info

setup:          ## First-time setup (create venv, install deps)
	uv venv
	VIRTUAL_ENV=.venv uv pip install -e ".[dev,docs]"

help:           ## Show available targets
	@grep -E '^[a-z].*:.*##' Makefile | column -t -s '##'
