.PHONY: help venv install dev test test-fast lint format typecheck check clean serve mcp doctor

PYTHON ?= python3.12
VENV   ?= .venv
BIN     = $(VENV)/bin

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

venv: ## Create the local virtualenv
	uv venv $(VENV) 2>/dev/null || $(PYTHON) -m venv $(VENV)
	@echo "Activate with: source $(BIN)/activate"

install: venv ## Install the package (editable) with dev extras
	uv pip install --python $(BIN)/python -e ".[dev]" 2>/dev/null || $(BIN)/pip install -e ".[dev]"

dev: install ## Alias for install

test: ## Run the full test suite
	$(BIN)/pytest

test-fast: ## Run tests, fail fast, verbose
	$(BIN)/pytest -x -v

lint: ## Lint with ruff
	$(BIN)/ruff check .

format: ## Auto-format with ruff
	$(BIN)/ruff format .

typecheck: ## Static type-check with mypy
	$(BIN)/mypy finn_eiendom

check: lint typecheck test ## Run lint + typecheck + tests

clean: ## Remove caches and build artifacts
	rm -rf .pytest_cache .ruff_cache .mypy_cache build dist *.egg-info
	find . -type d -name __pycache__ -prune -exec rm -rf {} +

serve: ## Start the MCP server over HTTP on port 8010
	$(BIN)/finn-eiendom serve --transport http --port 8010

mcp: ## Start the MCP server over stdio
	$(BIN)/finn-eiendom-mcp

doctor: ## Smoke-check the install
	$(BIN)/finn-eiendom doctor
