#!/bin/bash

print_help () {
    echo "Starts specified services in separate docker containers. If no option specified, starts all services including kafka"
    echo ""
    echo "options:"
    echo "-h, --help            show help"
    echo "--detection           start detection service"
    echo "--tracking            start tracking service"
    echo "--pose3d              start 3d pose estimation service"
    echo "--distance            start distance estimation service"
    echo "--actions             start actions classification service"
    echo "--kafka               start kafka on 9092 port without SSL authentication"
}

devbeh_all=true
devbeh_detection=false
devbeh_tracking=false
devbeh_pose3d=false
devbeh_distance=false
devbeh_actions=false
devbeh_kafka=false
while test $# -gt 0; do
    case "$1" in
        -h|--help)
            print_help
            exit 0
            ;;
        --detection)
            devbeh_all=false
            devbeh_detection=true
            shift
            ;;
        --tracking)
            devbeh_all=false
            devbeh_tracking=true
            shift
            ;;
        --pose3d)
            devbeh_all=false
            devbeh_pose3d=true
            shift
            ;;
        --distance)
            devbeh_all=false
            devbeh_distance=true
            shift
            ;;
        --actions)
            devbeh_all=false
            devbeh_actions=true
            shift
            ;;
        --kafka)
            devbeh_all=false
            devbeh_kafka=true
            shift
            ;;
        *)
            shift
            ;;
    esac
done

devbeh_services=""
if [ "$devbeh_all" = true ] || [ "$devbeh_kafka" = true ]; then
  devbeh_services="$devbeh_services kafka"
fi

if [ "$devbeh_all" = true ] || [ "$devbeh_detection" = true ]; then
  devbeh_services="$devbeh_services detection"
fi

if [ "$devbeh_all" = true ] || [ "$devbeh_tracking" = true ]; then
  devbeh_services="$devbeh_services tracking"
fi

if [ "$devbeh_all" = true ] || [ "$devbeh_pose3d" = true ]; then
  devbeh_services="$devbeh_services pose3d"
fi

if [ "$devbeh_all" = true ] || [ "$devbeh_distance" = true ]; then
  devbeh_services="$devbeh_services distance"
fi

if [ "$devbeh_all" = true ] || [ "$devbeh_actions" = true ]; then
  devbeh_services="$devbeh_services actions"
fi

current_dir=$(pwd)
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
# shellcheck disable=SC2086
docker-compose up -d $devbeh_services
cd "$current_dir" || exit 1