VENV := .venv
BIN := $(VENV)/bin

.PHONY: help install format lint typecheck test check build publish clean distclean

help: ## Show this help
	@grep -E '^[a-z][a-z_-]+:.*##' Makefile | sed 's/:.*## /\t/' | column -t -s '	'

install: ## Create venv and install package with dev deps
	python3 -m venv $(VENV)
	$(BIN)/pip install -e ".[dev]"

format: ## Format code and auto-fix lint issues
	$(BIN)/ruff format src tests
	$(BIN)/ruff check --fix src tests

lint: ## Check code style and lint rules
	$(BIN)/ruff check src tests

typecheck: ## Run mypy strict type checking
	$(BIN)/mypy src

test: ## Run tests with coverage
	$(BIN)/pytest --cov=xproject_creator --cov-report=term-missing -xvs

check: format lint typecheck test ## Run all checks (format + lint + typecheck + test)

build: ## Build sdist and wheel
	$(BIN)/python -m build

publish: build ## Publish to PyPI (requires TWINE_USERNAME/TWINE_PASSWORD or ~/.pypirc)
	$(BIN)/twine upload dist/*

clean: ## Remove caches and build artifacts
	rm -rf __pycache__ src/**/__pycache__ tests/__pycache__
	rm -rf .pytest_cache .mypy_cache .ruff_cache
	rm -rf dist build *.egg-info src/*.egg-info

distclean: clean ## Clean + remove venv
	rm -rf $(VENV)
