.PHONY: help install test lint format run smoke clean build publish-check

PYTHON ?= python3
PIP ?= pip
SDK_ROOT ?= ../sovaria-sdk

BLUE := \033[0;34m
GREEN := \033[0;32m
NC := \033[0m

help: ## Show this help message
	@echo '$(BLUE)Sovaria CLI - Available Commands:$(NC)'
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[0;32m%-20s\033[0m %s\n", $$1, $$2}'

install: ## Install CLI in editable mode with local SDK
	@if [ -d "$(SDK_ROOT)/apps/sdk/python" ]; then \
		$(PIP) install -e "$(SDK_ROOT)/apps/sdk/python"; \
	fi
	$(PIP) install -e ".[dev]"

test: ## Run CLI tests
	$(PYTHON) -m pytest apps/cli/tests

lint: ## Run Python linters for CLI
	@ruff check apps/cli || true

format: ## Format CLI Python code
	@ruff format apps/cli

run: ## Show CLI help
	@$(PYTHON) -m apps.cli.src.main --help

smoke: ## Run CLI/SDK happy path smoke test
	@bash scripts/cli_sdk_happy_path.sh

build: ## Build installable wheel
	$(PYTHON) -m build

publish-check: build ## Validate wheel metadata before PyPI upload
	$(PYTHON) -m twine check dist/*

clean: ## Remove local generated Python artifacts
	@find . -type d \( -name "__pycache__" -o -name ".pytest_cache" -o -name ".ruff_cache" -o -name "dist" -o -name "build" -o -name "*.egg-info" \) -prune -exec rm -rf {} +
	@echo '$(GREEN)✓ Cleaned CLI repo$(NC)'
