.PHONY: help install dev test lint format typecheck clean build docs

PYTHON := python3
UV := uv
VENV := codeCTO-env

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

venv: ## Create virtual environment
	$(UV) venv $(VENV) --python 3.12
	@echo "Activate with: source $(VENV)/bin/activate"

install: ## Install in production mode
	$(UV) pip install .

dev: ## Install in development mode with all extras
	$(UV) pip install -e ".[dev]"

dev-all: ## Install with all extras (AI, dashboard, tree-sitter)
	$(UV) pip install -e ".[all]"

test: ## Run tests
	pytest tests/ -v --tb=short

test-cov: ## Run tests with coverage
	pytest tests/ -v --cov=src/codecto --cov-report=html --cov-report=term-missing

test-unit: ## Run only unit tests
	pytest tests/unit/ -v

test-integration: ## Run only integration tests
	pytest tests/integration/ -v -m integration

lint: ## Run linter
	ruff check src/ tests/

lint-fix: ## Run linter with auto-fix
	ruff check src/ tests/ --fix

format: ## Format code
	ruff format src/ tests/

format-check: ## Check code formatting
	ruff format src/ tests/ --check

typecheck: ## Run type checker
	mypy src/codecto

check: lint format-check typecheck test ## Run all checks

clean: ## Clean build artifacts
	rm -rf build/ dist/ *.egg-info .pytest_cache .mypy_cache .ruff_cache htmlcov/ .coverage
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true

build: clean ## Build distribution packages
	$(PYTHON) -m build

scan: ## Run codecto on itself (dogfooding)
	codecto scan

scan-full: ## Run full codecto scan on itself
	codecto scan --profile enterprise
