#!/usr/bin/env bash
# SYS-CLOUD-9530 — EasySafe Cloud Server CLI.
# setup delegiert an das installierte install.sh (SYS-CLOUD-9500) —
# EINE Setup-Logik, kein Duplikat.
set -euo pipefail

BASE="/opt/easysafe-server"
COMPOSE=(docker compose -f "$BASE/docker-compose.cloud.yml" --env-file "$BASE/.env")

usage() {
  cat <<'EOF'
Usage: easysafe-server <command>

  setup    Erstkonfiguration (Domain, Admin) + Start + Template-Push
  start    Container starten
  stop     Container stoppen (Daten bleiben)
  status   Container-Status anzeigen
  update   Neue Images ziehen und Container aktualisieren
EOF
}

case "${1:-}" in
  setup)
    cd "$BASE" && exec ./install.sh
    ;;
  start)
    "${COMPOSE[@]}" up -d
    ;;
  stop)
    "${COMPOSE[@]}" stop
    ;;
  status)
    "${COMPOSE[@]}" ps
    ;;
  update)
    "${COMPOSE[@]}" pull
    "${COMPOSE[@]}" up -d
    ;;
  *)
    usage
    exit 1
    ;;
esac
