#!/usr/bin/env bash
set -e

if [[ "${1:-}" == "--smoke-test" ]]; then
  echo '{"app":"diagnostics-toolkit-shell","platform":"linux"}'
  exit 0
fi

echo "=== Diagnostics Toolkit Shell (Linux) ==="
echo "1. Info sistem"
echo "2. Info jaringan"
echo "3. Top proses"
echo "4. Ekspor laporan"
echo "0. Keluar"

read -r -p "Pilih menu: " choice
mkdir -p "$(dirname "$0")/data"

case "$choice" in
  1)
    uname -a
    free -h || true
    ;;
  2)
    ip addr || ifconfig || true
    ;;
  3)
    ps aux --sort=-%cpu | head -n 6
    ;;
  4)
    {
      echo "=== SYSTEM ==="
      uname -a
      echo
      echo "=== DISK ==="
      df -h
    } > "$(dirname "$0")/data/diagnostics-report.txt"
    echo "Laporan tersimpan."
    ;;
  0)
    echo "Selesai."
    ;;
  *)
    echo "Menu tidak valid."
    ;;
esac
