.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

clean:
	rm -rf env .coverage .pytest_cache .cache coverage.xml pyunit.xml output.log
	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 -v \
		--cov src \
		--cov-report term-missing

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

docker_up:
	docker compose up --build -d function

docker_down:
	docker compose down --remove-orphans

docker_event: docker_restart
	curl -X POST \
		-H 'Content-Type: application/json' \
		-d @tests/sample_msk_event.json \
		http://localhost:9000/2015-03-31/functions/function/invocations

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-review-queue-populate \
		lint-and-test

ci_unit_lint_clean: docker_down
	docker rm -f lambda-content-review-queue-populate
