.PHONY: help install update-install pre-commit build run test test-live app coverage \
	show-coverage cache-clear cleanup-tests site lint format \
	ci-lint-flake8 ci-lint-mypy ci-test pre-commit-manual

.DEFAULT: help
help:
	@echo "make install"
	@echo "       install all the dependencies specified in pyproject.toml and uv.lock"
	@echo "make update-install"
	@echo "       runs uv lock without updates and installs all the dependencies specified in pyproject.toml and uv.lock"
	@echo "make pre-commit"
	@echo "       install the pre-commit and pre-push hooks"
	@echo "make build"
	@echo "       packages the application in wheel format"
	@echo "make run"
	@echo "       run the app (python -m katunog)"
	@echo "make test"
	@echo "       run tests and coverage checks"
	@echo "make test-live"
	@echo "       run the opt-in live smoke suite against the real Katunog server"
	@echo "make app"
	@echo "       ensures that the branch is ready to push"
	@echo "make coverage"
	@echo "       generate the coverage.json report"
	@echo "make show-coverage"
	@echo "       run coverage checks and open the html report"
	@echo "make site"
	@echo "       run tests and generate the html coverage report"
	@echo "make cache-clear"
	@echo "       remove *_cache* directories"
	@echo "make cleanup-tests"
	@echo "       run cleanup of test/cache/report files"
	@echo "make pre-commit-manual"
	@echo "       run isort, black, flake8, mypy, tests and coverage checks"
	@echo "make lint"
	@echo "       run flake8 and mypy"
	@echo "make format"
	@echo "       run isort and black"
	@echo "make ci-lint-flake8"
	@echo "       run flake8 for CI"
	@echo "make ci-lint-mypy"
	@echo "       run mypy for CI with a junit report"
	@echo "make ci-test"
	@echo "       run tests for CI with an xml coverage report"
	@echo "make help"
	@echo "       print this help message"

install:
	uv sync

update-install:
	uv lock
	uv sync

pre-commit:
	uv run pre-commit install -t pre-commit
	uv run pre-commit install -t pre-push

build:
	uv build

run:
	uv run python -m katunog

test:
	uv run pytest -v --cov --cov-branch -p no:cacheprovider
	make coverage
	make cleanup-tests

test-live:
	uv run pytest -v -m live --no-cov

app:
	make update-install
	make pre-commit-manual

coverage:
	uv run coverage json

show-coverage:
	uv run pytest -v --cov --cov-report=html
	open reports/site/index.html

cache-clear:
	find . -type d -name "*_cache*" -exec rm -rf {} +

cleanup-tests:
	# for reports folders
	find ./tests -type d -name "reports" -exec rm -rf {} +
	rm -rf reports

	# for cache
	make cache-clear

	# for coverage results
	find . \( -name "test-output.xml" -o -name "coverage.xml" -o -name "coverage.json" -o -name ".coverage" \) -delete

site:
	uv run pytest -v --cov --cov-report=html

lint:
	mkdir -p reports
	uv run flake8
	uv run mypy

format:
	uv run isort .
	uv run black .

ci-lint-flake8:
	mkdir -p reports
	uv run flake8

ci-lint-mypy:
	uv run mypy --junit-xml reports/lint-mypy.xml

ci-test:
	uv run pytest -v --cov --cov-report=xml --cov-branch
	make coverage

pre-commit-manual:
	uv run isort .
	uv run black .
	uv run flake8
	uv run mypy
	make test
