.PHONY: install dev test test-unit test-integration lint type-check format clean build publish

# ──────────────────────────────────────────────
#  Setup
# ──────────────────────────────────────────────

install:  ## Install SDK in current env
	pip install -e .

dev:  ## Install SDK + dev dependencies
	pip install -e ".[dev]"
	pre-commit install

# ──────────────────────────────────────────────
#  Testing
# ──────────────────────────────────────────────

test:  ## Run all tests
	pytest tests/ -v --cov --cov-report=term-missing

test-unit:  ## Run unit tests only (no network)
	pytest tests/unit/ -v -m "not integration"

test-integration:  ## Run integration tests (requires backend + API keys)
	pytest tests/integration/ -v -m integration

test-providers:  ## Run provider-specific tests
	pytest tests/unit/test_providers.py -v

# ──────────────────────────────────────────────
#  Code Quality
# ──────────────────────────────────────────────

lint:  ## Lint with ruff
	ruff check src/ tests/

format:  ## Format with ruff
	ruff format src/ tests/
	ruff check --fix src/ tests/

type-check:  ## Type-check with mypy
	mypy src/promptline/

check: lint type-check test-unit  ## Run all checks (pre-commit equivalent)

# ──────────────────────────────────────────────
#  Build & Publish
# ──────────────────────────────────────────────

build:  ## Build distribution packages
	python -m build

publish-test:  ## Publish to TestPyPI
	python -m twine upload --repository testpypi dist/*

publish:  ## Publish to PyPI (requires PyPI token)
	python -m twine upload dist/*

# ──────────────────────────────────────────────
#  Cleanup
# ──────────────────────────────────────────────

clean:  ## Remove build artifacts
	rm -rf dist/ build/ *.egg-info src/*.egg-info
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
	find . -name "*.pyc" -delete 2>/dev/null || true

# ──────────────────────────────────────────────
#  Help
# ──────────────────────────────────────────────

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

.DEFAULT_GOAL := help
