#!/bin/bash

# Set the parent directory
parentDir="/c/xampp/htdocs/eGovApp"

# Function to run a command in a new Git Bash session
function run_in_git_bash {
    dir="$1"
    command="$2"
    mintty bash -c "cd \"$dir\" && $command" &
}

# Run the dua.backend project in a new Git Bash session
run_in_git_bash "$parentDir/dua.backend" "php artisan bff:work"

# Loop through the other Laravel project directories and start the RabbitMQ reader in new Git Bash sessions
laravelDirs=("ms.riview" "ms.dpass" "ms.rescom" "ms.papyros" "ms.support" "ms.contacts" "ms.notifications" "ms.net_support")
for dir in "${laravelDirs[@]}"; do
    run_in_git_bash "$parentDir/$dir" "php artisan rabbitmq:read"
done

# Run the mail queue for ms.contacts in a new Git Bash session
run_in_git_bash "$parentDir/ms.contacts" "php artisan mail:work"

# Run the mail queue for ms.notifications in a new Git Bash session
run_in_git_bash "$parentDir/ms.notifications" "php artisan notification:work"

# Wait for all background processes to finish
wait

# Return to the original directory (optional)
cd "$parentDir"
