.PHONY: env clean test_unit up down logs
.PHONY: restart fmt lint

env:
	poetry install

clean:
	rm -rf env .cache .pytest_cache .mypy_cache .ruff_cache pyunit.xml .coverage coverage.xml
	find . | grep -E '__pycache__|\.pyc|\.pyo$\' | xargs rm -rf

test_unit:
	docker compose up --build lint-and-test

up:
	docker compose up --build -d function

down:
	docker compose down function

logs:
	docker logs -f token_secret_rotation-function-1

restart:
	docker compose restart function

lint: env
	poetry run mypy src/ tests/ config.py
	poetry run ruff check src tests config.py
	poetry run ruff format src tests config.py --check --diff

fmt:  env ## Run code formatters
	poetry run ruff check config.py src tests --fix
	poetry run ruff format src config.py tests

test_event:
	curl --request POST \
		--url http://localhost:9000/2015-03-31/functions/function/invocations \
		--header 'Content-Type: application/json' \
		--data-binary "@tests/sample_event.json"

ci_test_integration:
	docker compose up \
		--build \
		--exit-code-from integration-test \
		--abort-on-container-exit \
		--remove-orphans \
		integration-test
