.PHONY: dev sync lint fmt test test_unit test_integration clean clean_test_integration

dev: dev.py
	FLASK_ENV=development uv run python dev.py

sync:
	uv sync --group dev

fmt: reporting tests/ dev.py
	uv run ruff format reporting/ tests/ dev.py

lint: reporting tests/ dev.py
	uv run ruff check reporting/ tests/ dev.py

test: tests/
	uv run py.test tests/

test_unit: reporting tests/
	uv run py.test \
		--ignore=tests/integration \
		--cov reporting tests/ \
		--cov-report xml \
		--junitxml=pyunit.xml

test_integration:
	uv run py.test tests/integration --noconftest

test_docker_all:
	TEST_ARGS="-sv" docker compose up --exit-code-from unit-lint --abort-on-container-exit --build unit-lint

docker_unit_lint:  ## Run lint and unit tests in Docker
	TEST_ARGS="--ignore=tests/integration" docker compose up \
		--build \
		--exit-code-from unit-lint \
		--abort-on-container-exit \
		--remove-orphans \
		unit-lint

down_unit_lint:  ## Teardown any remaining Docker containers related to lint and unit tests
	docker compose down unit-lint --remove-orphans

ci_unit_lint: ci_unit_lint_clean  ## Run lint and unit tests in CI/CD
	chmod +x lint-and-test.sh
	mkdir -p reports
	chmod a+w reports
	make docker_unit_lint

ci_unit_lint_clean: down_unit_lint  ## Teardown lint and unit tests in CI/CD
	rm -rf reports

test_docker_integration:
	TESTS="tests/integration --noconftest" docker compose up --exit-code-from unit-lint --abort-on-container-exit --build unit-lint

clean:
	rm -rf .venv

clean_test_integration:
	rm -rf tests/integration/.venv