#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"

ACTION="${1:-start}"
SERVICE="${2:-php1}"

case "$ACTION" in
  start)
    docker compose up -d traefik redis mysql-debug php1 caddy
    ;;
  stop)
    docker compose down
    ;;
  logs)
    docker compose logs -f --tail=200 "$SERVICE"
    ;;
  test)
    docker compose exec -T php1 sh -lc "cd /var/www/html && composer test:unit"
    ;;
  *)
    echo "Usage: ./scripts/run.sh [start|stop|logs <service>|test]"
    exit 1
    ;;
esac
