.PHONY: help install lint type test test-unit test-integration audit cov db-upgrade db-downgrade clean demo-stack-up demo-stack-down

PY := uv run

help:
	@echo "make install         install deps (incl. dev)"
	@echo "make lint            ruff check"
	@echo "make type            mypy strict"
	@echo "make test            run unit tests"
	@echo "make test-integration run integration tests"
	@echo "make audit           scan dependencies for known CVEs (pip-audit)"
	@echo "make cov             coverage report"
	@echo "make db-upgrade      alembic upgrade head"
	@echo "make db-downgrade    alembic downgrade -1"
	@echo "make clean           remove caches and artefacts"

install:
	uv sync --all-extras

lint:
	$(PY) ruff check src tests

type:
	$(PY) mypy

test test-unit:
	$(PY) pytest tests/unit -v

test-integration:
	$(PY) pytest tests/integration -v -m integration

audit:
	$(PY) --with pip-audit pip-audit

cov:
	$(PY) pytest --cov=tubekit --cov-report=term-missing tests/unit

db-upgrade:
	$(PY) alembic upgrade head

db-downgrade:
	$(PY) alembic downgrade -1

clean:
	rm -rf .pytest_cache .ruff_cache .mypy_cache htmlcov .coverage
	find . -type d -name __pycache__ -exec rm -rf {} +

demo-stack-up:
	docker compose -f docker-compose.demo.yml up -d
	@echo "Jaeger:     http://localhost:16686"
	@echo "Prometheus: http://localhost:9090"
	@echo "Grafana:    http://localhost:3000 (anonymous admin)"
	@echo "Point the server at the collector: export TUBEKIT_OTLP_ENDPOINT=http://localhost:4317"

demo-stack-down:
	docker compose -f docker-compose.demo.yml down -v
