.PHONY: up down seed invoke install logs console clean graphs docs kind tilt-up tilt-down

PY ?= .venv/bin/python
PIP ?= .venv/bin/pip
COMPOSE := docker compose -f ctrl/docker-compose.yml
DOT_SRC := $(wildcard docs/graphs/*.dot)
SVG_OUT := $(DOT_SRC:.dot=.svg)

install:
	python3 -m venv .venv
	$(PIP) install -U pip
	$(PIP) install -r requirements.txt

up:
	$(COMPOSE) up -d
	@echo "MinIO API:     http://localhost:9000"
	@echo "MinIO console: http://localhost:9001  (minioadmin / minioadmin)"

down:
	$(COMPOSE) down

clean:
	$(COMPOSE) down -v

logs:
	$(COMPOSE) logs -f minio

kind:
	bash ctrl/kind-config.sh

tilt-up:
	cd ctrl && tilt up --context kind-eth

tilt-down:
	cd ctrl && tilt down --context kind-eth

seed:
	@if [ -z "$$SOURCE_DIR" ]; then echo "set SOURCE_DIR=<path-to-pdfs>"; exit 2; fi
	$(PY) seed.py "$$SOURCE_DIR"

invoke:
	$(PY) invoke.py

console:
	xdg-open http://localhost:9001 >/dev/null 2>&1 || true

docs/graphs/%.svg: docs/graphs/%.dot
	dot -Tsvg $< -o $@

graphs: $(SVG_OUT)
	@echo "rendered $(words $(SVG_OUT)) svg(s) from $(words $(DOT_SRC)) dot file(s)"

docs: $(SVG_OUT)
	xdg-open docs/index.html >/dev/null 2>&1 || echo "open docs/index.html in your browser"
