# WordForge — developer shortcuts
.PHONY: help install sync lock dev test test-unit test-integration lint fmt typecheck precommit clean docker-build docker-up docker-down spacy

PYTHON ?= python
UV     ?= uv

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

install: ## Install all deps (dev included) and pre-commit hooks
	$(UV) sync --all-extras
	$(UV) run pre-commit install --hook-type pre-commit --hook-type commit-msg

sync: ## uv sync (no extras)
	$(UV) sync

lock: ## Refresh uv.lock
	$(UV) lock

spacy: ## Install the spaCy en_core_web_sm model (wheel, no pip needed)
	$(UV) pip install "en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whl"

dev: ## Run the API locally (hot reload)
	$(UV) run uvicorn wordforge.api.main:app --host 0.0.0.0 --port 8001 --reload

cli: ## Run the WordForge CLI ('make cli ARGS="--help"')
	$(UV) run wordforge $(ARGS)

test: ## Run the full test suite
	$(UV) run pytest

test-unit: ## Run unit tests only
	$(UV) run pytest -m "not integration"

test-integration: ## Run integration tests only
	$(UV) run pytest -m integration

lint: ## Lint with ruff
	$(UV) run ruff check .

fmt: ## Format with ruff
	$(UV) run ruff format .
	$(UV) run ruff check --fix .

typecheck: ## Type check with mypy
	$(UV) run mypy src/

precommit: ## Run all pre-commit hooks on all files
	$(UV) run pre-commit run --all-files

docker-build: ## Build the Docker image
	docker compose build

docker-up: ## Start the stack (detached)
	docker compose up -d

docker-down: ## Stop the stack
	docker compose down

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