.PHONY: build dev-backend dev-frontend test lint format clean help

# Variables
FRONTEND_DIR = frontend
PYTHON = uv run

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

build: ## Compila frontend + genera wheel distribuible
	cd $(FRONTEND_DIR) && npm run build
	uv build

dev-backend: ## Inicia FastAPI en modo desarrollo con auto-reload
	$(PYTHON) fastapi dev atipflow/main.py --host 0.0.0.0 --port 8000

dev-frontend: ## Inicia Vite dev server con HMR
	cd $(FRONTEND_DIR) && npm run dev

test: ## Ejecuta tests con pytest + coverage
	$(PYTHON) pytest tests/ -v --cov=atipflow --cov-report=term-missing

lint: ## Lint con ruff
	$(PYTHON) ruff check .
	$(PYTHON) ruff format --check .

format: ## Formatea código con ruff
	$(PYTHON) ruff format .

clean: ## Limpia artefactos de build
	rm -rf atipflow/static dist *.egg-info .coverage htmlcov
