.PHONY: .uv
.uv: ## Check that uv is installed
	@uv --version || echo "Please make sure uv is installed"

.PHONY: .pre-commit
.pre-commit: ## Check that pre-commit is installed
	@uv run pre-commit -V || echo "Please make sure pre-commit is installed"

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

.PHONY: generate-lock-file
generate-lock-file: .uv ## Generate a uv.lock file from pyproject.toml
	@uv lock

.PHONY: sync
sync: .uv ## Sync local environment for Python development on pipelines
	@uv sync --all-extras --all-groups

.PHONY: pre-commit-install
pre-commit-install: .uv .pre-commit ## Install pre-commit hooks
	@uv run pre-commit install

.PHONY: pre-commit
pre-commit: .uv .pre-commit ## Runs the pre-commit checks over entire repo
	@uv run pre-commit run --all-files --color=always

.PHONY: ruff
ruff: .uv .pre-commit ## Runs ruff linting and formatting
	@if [ -n "$(path)" ]; then \
		uv run ruff check --fix $(path) && \
		uv run ruff format $(path); \
	else \
		uv run ruff check --fix && \
		uv run ruff format; \
	fi

.PHONY: pyright
pyright: .uv .pre-commit ## Runs pyright type checking
	@if [ -n "$(path)" ]; then \
		uv run pyright $(path); \
	else \
		uv run pyright; \
	fi

.PHONY: run-tests
run-tests: .uv .pre-commit ## Run tests
	@if [ -n "$(path)" ]; then \
		uv run coverage run -m pytest $(path); \
	else \
		uv run coverage run -m pytest; \
	fi

.PHONY: run-tests-cov
run-tests-cov: .uv .pre-commit ## Run tests with coverage
	@uv run pytest -n auto --cov=src tests

.PHONY: changelog
changelog: ## Regenerate CHANGELOG.md via git-cliff
	@git-cliff -o CHANGELOG.md

.PHONY: clean
clean: ## Remove generated files like __pycache__, .coverage, etc.
	@find . -type d -name "__pycache__" -exec rm -rf {} +
	@find . -type f -name "*.pyc" -delete
	@find . -type f -name "*.pyo" -delete
	@find . -type f -name "*.pyd" -delete
	@find . -type d -name "*.egg-info" -exec rm -rf {} +
	@find . -type d -name "*.egg" -exec rm -rf {} +
	@find . -type f -name ".coverage" -delete
	@find . -type d -name "htmlcov" -exec rm -rf {} +
	@find . -type d -name ".pytest_cache" -exec rm -rf {} +
	@find . -type d -name ".ruff_cache" -exec rm -rf {} +
	@find . -type d -name ".mypy_cache" -exec rm -rf {} +
	@find . -type d -name ".pyright_cache" -exec rm -rf {} +
	@rm -rf dist/ build/ .coverage .coverage.* .venv +
	@uv cache clean

.PHONY: setup-venv
setup-venv: clean sync pre-commit-install ## Clean, sync, and install pre-commit hooks
