#!/bin/bash
# scripts/dev.sh – lokaler Dev-Launcher für ReBreak-Apps
#
# Wichtig: Backend wird NICHT gestartet. Die Apps laufen gegen den
# konfigurierten Server (z. B. staging.rebreak.org). Backend nur lokal
# entwickeln/testen, wenn explizit `backend` übergeben wird.
#
# Usage:
#   ./scripts/dev.sh magic    # apps/rebreak-magic Tauri-Dev (gegen Server)
#   ./scripts/dev.sh admin    # apps/admin Nuxt-Dev
#   ./scripts/dev.sh native   # apps/rebreak-native Expo-Start
#   ./scripts/dev.sh backend  # backend Nitro-Dev (lokales Backend)

set -euo pipefail

REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
APP="${1:-}"

log() { echo "[dev] $*"; }

if [[ -z "$APP" ]]; then
  echo "Usage: $0 <magic|magic2|admin|native|backend>"
  exit 1
fi

cd "$REPO_ROOT"

case "$APP" in
  magic|magic2)
    log "Starte ReBreak Magic (Tauri-Dev, gegen konfigurierten Server)..."
    cd apps/rebreak-magic
    pnpm tauri:dev
    ;;
  admin)
    log "Starte Admin-App (Nuxt-Dev)..."
    pnpm --filter rebreak-admin dev
    ;;
  native)
    log "Starte ReBreak Native (Expo)..."
    pnpm --filter rebreak-native start
    ;;
  backend)
    log "Starte Backend lokal (Nitro-Dev)..."
    pnpm --filter rebreak-backend dev
    ;;
  *)
    echo "Unbekannte App: $APP"
    echo "Usage: $0 <magic|magic2|admin|native|backend>"
    exit 1
    ;;
esac
