#!make
SHELL := /bin/bash
GIT_HASH ?= $(shell git log --format="%h" -n 1)
export VERSION=$(if $(v),$(v),latest)

include .env
-include .env.local
export

.PHONY: help build test up down exec clean

help: ## Help command
	@echo
	@cat Makefile | grep -E '^[a-zA-Z\/_-]+:.*?## .*$$' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
	@echo

up: ## Start the backend containers
	@docker-compose --profile backend up -d

down: ## Stop the backend containers
	@docker-compose --profile backend down

run: ## Run the project
	@echo "Running project..."
	@cargo run
	@echo "Run complete"

format: ## Format code
	@echo "Formatting code..."
	@cargo fmt
	@echo "Format complete"

clean: ## Clean the project
	@echo "Cleaning project..."
	@cargo clean
	@echo "Clean complete"

docker-up: ## Start the app
	@docker-compose --profile backend --profile siren up -d

docker-down: ## Stop the app
	@docker-compose --profile backend --profile siren down

docker-build: ## Build the docker image
	@docker-compose build

docker-clean: ## Stop the docker containers and remove volumes
	@echo "Stopping docker container and removing volumes..."
	@docker-compose --profile backend --profile siren down -v
	@echo "Docker container stopped and volumes removed"

refresh: docker-clean up ## Refresh the docker containers