# Add any tasks that are not dependent on files to the .PHONY list.
.PHONY: clean dev env pip_dev lint docker_up docker_down \
            down_unit_lint docker_unit_lint \
            test test_unit ci_unit_lint ci_unit_lint_clean

env pip_dev:  ## Prepare environment
	poetry install --extras dev

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

dev: env  # Run dev application
	poetry run python dev.py


lint: pip_dev  ## Run code linters
	poetry run mypy product_store_mapping tests
	poetry run ruff check product_store_mapping tests application.py
	poetry run ruff format product_store_mapping tests application.py --diff

fmt:  pip_dev ## Run code formatters
	poetry run ruff check product_store_mapping tests application.py --fix
	poetry run ruff format product_store_mapping tests application.py

docker_unit_lint:  # Run lint and unit tests in Docker
	docker compose up \
		--build \
		--exit-code-from unit-lint \
		--abort-on-container-exit \
		--remove-orphans \
		unit-lint

ci_unit_lint: ci_unit_lint_clean  # Run lint and unit tests in CI/CD
	mkdir -p build
	chmod a+w build
	make docker_unit_lint

ci_unit_lint_clean: down_unit_lint  # Teardown lint and unit tests in CI/CD
	rm -rf build

down down_deploy down_unit_lint:  # Bring down all docker containers
	docker compose down --remove-orphans

up_deploy:  # Bring up dockerized deploy service
	docker compose up \
		--build \
		--detach \
		--remove-orphans \
		deploy

test_integration:
	echo "noop for now, need integration tests"
