.PHONY: help install dev-install setup-hooks \
        format lint type-check security \
        test test-cov coverage-diff \
        ci ci-fast clean run

# ------------------------
# 📚 Help
# ------------------------
help:
	@echo "Available commands:"
	@echo "  make install         - Install production dependencies"
	@echo "  make dev-install     - Install all dependencies + hooks"
	@echo "  make setup-hooks     - Install pre-commit hooks"
	@echo "  make format          - Format code (ruff)"
	@echo "  make lint            - Lint code (ruff)"
	@echo "  make type-check      - Run type checking (ty)"
	@echo "  make security        - Run security checks (bandit)"
	@echo "  make test            - Run tests"
	@echo "  make test-cov        - Run tests with coverage"
	@echo "  make ci              - Full CI locally"
	@echo "  make ci-fast         - CI without slow steps"
	@echo "  make clean           - Clean cache files"

# ------------------------
# 📦 Install
# ------------------------
install:
	uv sync --no-dev --all-extras

dev-install:
	uv sync --group dev --all-extras
	uv run pre-commit install
	uv run pre-commit install --hook-type commit-msg
	@echo "✅ Dev environment ready"

setup-hooks:
	uv run pre-commit install
	uv run pre-commit install --hook-type commit-msg

# ------------------------
# 🧹 Code quality
# ------------------------
format:
	uv run ruff format .
	uv run ruff check --fix .

lint:
	uv run ruff check .

type-check:
	uv run ty check .

security:
	uv run bandit -c pyproject.toml -r .

# ------------------------
# 🧪 Tests
# ------------------------
test:
	uv run pytest

test-cov:
	uv run pytest \
		--cov=src \
		--cov-report=term \
		--cov-report=xml:coverage.xml \
		--cov-fail-under=80

# ------------------------
# 🚀 CI equivalent
# ------------------------
ci: lint type-check security test-cov
	@echo ""
	@echo "✅ Full CI checks passed"

# Faster version (no bandit blocking)
ci-fast: lint type-check test
	@echo ""
	@echo "⚡ Fast CI checks passed"

# ------------------------
# 🧹 Cleanup
# ------------------------
clean:
	find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name "*.pyc" -delete 2>/dev/null || true
	rm -rf .pytest_cache .ruff_cache .ty_cache htmlcov coverage.xml 2>/dev/null || true
