.PHONY: format lint clean_html_report docker_run_cross_lambda_integration_tests test_integration test_cross

# Root directory of the tests: lambda-documents/tests
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

format:
	ruff check . *.py --fix
	ruff format . *.py

lint:
	ruff check . *.py
	ruff format . *.py --check --diff
	yamllint -s docker-compose.yaml
	mypy cross_lambda_integration/ integration/ models/ utils/ config.py

clean_html_report:
	rm -r report || true
	mkdir report

## Run tests for a specific lambda
test_integration:
ifeq ($(function),)
	@echo "❌ Please provide a lambda function name: make test_integration function='lambda_name'"
	@exit 1
else
	@echo "▶ Running integration tests for lambda: $(function)"
	pytest $(ROOT_DIR)/integration/$(function)/test*.py --html=report/report_$(function).html --self-contained-html
endif

test_cross: ## Run cross-lambda integration tests
	@echo "▶ Running cross-lambda integration tests"
	pytest $(ROOT_DIR)/cross_lambda_integration/test*.py --html=report/report_cross_lambda.html --self-contained-html

docker_run_integration_tests: clean_html_report
	@echo "Building the lambda-integration-tests image for lambda integration test..."
	docker compose build lambda-integration-tests
	@echo "Running Lambda Integration Tests in Docker..."
	docker compose up lambda-integration-tests --exit-code-from lambda-integration-tests

docker_run_cross_lambda_tests: clean_html_report
	@echo "Building the cross-lambda-tests image for cross lambda tests..."
	docker compose build cross-lambda-tests
	@echo "Running Cross Lambda Tests in Docker..."
	docker compose up cross-lambda-tests --exit-code-from cross-lambda-tests
