.PHONY: clean pip_lock_versions pip_dev dev lint test
.PHONY: docker_up docker_down docker_event docker_restart
.PHONY: ci_unit_lint ci_unit_lint_clean
.PHONY: aws_os_proxy_up aws_os_proxy_down

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

env:
	../install_local_dependencies.sh -r env

env/bin/flake8 env/bin/py.test pip_dev: | env
	../install_local_dependencies.sh -r dev

lint: | env/bin/flake8
	env/bin/python -m flake8 src tests dev.py

dev: | env/bin/py.test
	env/bin/python dev.py

test: | env/bin/py.test
	env/bin/python -m pytest tests/unit \
		--cov src \
		--cov-report term-missing

pip_lock_versions: clean env
	../install_local_dependencies.sh -r lock

aws_os_proxy_up:
	docker compose up --build -d aws-os-proxy

aws_os_proxy_down:
	docker compose stop aws-os-proxy
	docker compose rm -f aws-os-proxy

docker_up:
	docker compose up --build -d function

docker_down:
	docker compose down --remove-orphans

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

docker_restart:
	docker compose restart function
	sleep 0.5  # Give the container time to restart.

ci_unit_lint:
	docker compose run \
		--rm \
		--build \
		--name lambda-content-index-queue-move \
		lint-and-test

ci_unit_lint_clean: docker_down
	docker rm -f lambda-content-index-queue-move
