.DEFAULT_GOAL := help
MAKEFLAGS += --no-print-directory

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

install: ## Install backend (uv) + frontend (npm) dependencies
	uv sync
	cd frontend && npm install

dev: ## Run backend (:8745) + frontend (:5173) with hot reload
	$(MAKE) -j2 dev-api dev-ui

dev-api: ## Run the FastAPI backend only (hot reload)
	uv run uvicorn --factory llmlinq.server:create_app --reload --port 8745

dev-ui: ## Run the Vite dev server only
	cd frontend && npm run dev

build-ui: ## Build the SPA into src/llmlinq/web/static/
	cd frontend && npm run build

build: build-ui ## Build the distributable wheel (UI bundled inside)
	uv build

test: ## Run the Python test suite
	uv run pytest

lint: ## ruff + mypy + tsc
	uv run ruff check src tests
	uv run ruff format --check src tests
	uv run mypy src
	cd frontend && npm run typecheck

fmt: ## Auto-format Python code
	uv run ruff check --fix src tests
	uv run ruff format src tests

clean: ## Remove build artifacts and caches
	rm -rf dist src/llmlinq/web/static .pytest_cache .mypy_cache .ruff_cache

.PHONY: help install dev dev-api dev-ui build-ui build test lint fmt clean
