.PHONY: help format lint fmt up down ps logs execute restart test
.DEFAULT_GOAL := help

# define root project dir
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

help:
	@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

format:
	uv sync --group test
	uv run ruff check src tests *.py --fix
	uv run ruff format src tests *.py

lint: ## Run code linters
	uv sync --group test
	uv run ruff check src tests *.py --diff
	uv run ruff format src tests *.py --check --diff
	uv run mypy src/ tests/ config.py

up:  ## Start container
	docker compose up --build -d function

down: ## Shutdown docker src
	docker compose down

ps: ## List all processes
	docker compose ps

logs: ## View logs
	docker compose logs -f

execute: ## Execute function
	curl --request POST \
	  --url http://localhost:9000/2015-03-31/functions/function/invocations \
	  --header 'Content-Type: srclication/json' \
	  --data @tests/sample_event.json

restart:  ## Load changes
	docker compose restart function

test:  ## Lint and test
	docker compose up --build lint-and-test