UV ?= uv

PKG := asyncbreaker
PATHS := asyncbreaker/ test/
TESTS := test/

.DEFAULT_GOAL := help

.PHONY: help sync lint format format-check type quality test test-cov build clean

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

sync: ## Install project + dev extras into .venv
	$(UV) sync

lint: ## Run ruff lint (incl. security S)
	$(UV) run ruff check $(PATHS)

format: ## Apply ruff auto-fixes and formatting
	$(UV) run ruff check $(PATHS) --fix
	$(UV) run ruff format $(PATHS)

format-check: ## Check ruff formatting
	$(UV) run ruff format --check $(PATHS)

type: ## Run mypy
	$(UV) run mypy $(PKG)

quality: ## Run mypy and ruff
	$(MAKE) type lint format-check

test: ## Run all tests
	$(UV) run pytest $(TESTS)

test-cov: ## Run tests with coverage
	$(UV) run pytest $(TESTS) --cov=$(PKG) --cov-report=term-missing --cov-report=xml

build: ## Build sdist and wheel
	$(UV) build
	$(UV) run --with twine twine check dist/*

clean: ## Clean temporary artifacts
	rm -rf .pytest_cache .coverage coverage.xml .mypy_cache .ruff_cache
	rm -rf build dist *.egg-info site
	find . -type d -name "__pycache__" -exec rm -rf {} +
	find . -type d -name "*.egg-info" -exec rm -rf {} +
