args := $(wordlist 2, 100, $(MAKECMDGOALS))
ifndef args
MESSAGE = "No such command (or you pass two or many targets to ). List of possible commands: make help"
else
MESSAGE = "Done"
endif

API_APPLICATION_NAME = api

services:
	docker-compose -f docker-compose.yaml up -d --remove-orphans

start-api:
	cd api && \
	source .venv/bin/activate && \
	python -m ${API_APPLICATION_NAME}

start-client:
	cd client && \
	npm start

migrate:
	cd api && \
	source .venv/bin/activate && \
	cd $(API_APPLICATION_NAME)/db && \
	PYTHONPATH='../..' ALEMBIC_MIGRATIONS=True alembic upgrade $(args)

downgrade:
	cd api && \
	source .venv/bin/activate && \
	cd $(API_APPLICATION_NAME)/db && \
	PYTHONPATH='../..' alembic downgrade -1

revision:
	cd api && \
	source .venv/bin/activate && \
	cd $(API_APPLICATION_NAME)/db && \
	PYTHONPATH='../..' ALEMBIC_MIGRATIONS=True alembic revision --autogenerate

venv-api:
	cd api && \
	poetry install

install:
	make migrate head && \
	cd api && \
	poetry run python3 api/utils/init.py

%::
	echo $(MESSAGE)