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

cmd="${1:-}"
shift || true

case "$cmd" in
  list)
    cat <<'EOL'
VMID       Status     Name
100 running ct-one
101 stopped -
EOL
    ;;
  exec)
    if [[ "${2:-}" == "--" && "${3:-}" == "ip" && "${4:-}" == "-j" ]]; then
      cat <<'EOL'
[{"ifname":"lo","addr_info":[{"family":"inet","local":"127.0.0.1"}]},{"ifname":"eth0","addr_info":[{"family":"inet","local":"192.168.178.102"},{"family":"inet6","local":"fe80::1"}]},{"ifname":"eth1","addr_info":[{"family":"inet","local":"10.0.0.8"}]}]
EOL
    fi
    ;;
  config)
    case "${1:-}" in
      101) echo "hostname: ct-fallback" ;;
      *) echo "hostname: ct-${1:-unknown}" ;;
    esac
    # PMAN_MOCK_ONBOOT_IDS: space separated VMIDs that report "onboot: 1".
    if [[ " ${PMAN_MOCK_ONBOOT_IDS:-} " == *" ${1:-} "* ]]; then
      echo "onboot: 1"
    fi
    ;;
  status)
    echo "status: running"
    ;;
  *)
    exit 0
    ;;
esac
