EXEC_OPT            =
COMPOSER_OPTS       =
DOCKER_COMPOSE      = USER_UID=$(shell id -u) USER_GID=$(shell id -g) docker-compose -f infrastructure/docker-compose.yml -f infrastructure/docker-compose.override.yml
.PHONY: help

# Detect system environment


help: ## Show help like directly using make
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'


install:  ## Install system dependencies
	# ***************************
	#  Install requirements
	# ***************************
	$(DOCKER_COMPOSE) build
	$(DOCKER_COMPOSE) run --rm php composer install
	$(DOCKER_COMPOSE) run --rm node npm install

run: ## Launch the electron app
#	make migration
	$(DOCKER_COMPOSE) run --rm php sh -c "./wait-for-it.sh -t 30 database:3306 && php artisan migrate"
	$(DOCKER_COMPOSE) up -d

stop: ## stop the infrastructure
	$(DOCKER_COMPOSE) stop

down: ## Delete the Docker containers and volumes
	$(DOCKER_COMPOSE) down -v

ps:
	$(DOCKER_COMPOSE) ps

cli:
	$(DOCKER_COMPOSE) exec php bash

logs:
	$(DOCKER_COMPOSE) logs --tail=10 -f

clean:
	$(DOCKER_COMPOSE) down
	rm -rf node_modules
	rm -rf vendor/

cache-clear:
	$(DOCKER_COMPOSE) exec php php artisan cache:clear

migration:
	$(DOCKER_COMPOSE) run --rm php php artisan migrate

fixtures:
	make migration
	$(DOCKER_COMPOSE) exec php php artisan db:seed

refresh-fixtures:
	$(DOCKER_COMPOSE) exec php php artisan migrate:fresh
	$(DOCKER_COMPOSE) exec php php artisan db:seed

prettier:
	docker run -v ${PWD}:/code ghcr.io/php-cs-fixer/php-cs-fixer:3.48-php8.2 fix -- ./app
