#!/usr/bin/env bash
# list.sh — muestra todos los agentes y su estado actual
# Uso: ./dev-scripts/agent/list.sh

source "$(dirname "$0")/../_common.sh"

printf "%-22s  %-12s  %-8s  %s\n" "ID" "STATUS" "VERSION" "DESCRIPTION"
printf '%s\n' "$(printf '─%.0s' {1..70})"

while IFS='|' read -r id version enabled desc _cfg; do
  status=$(agent_status "$id" "$enabled")

  case "$status" in
    running)  label="${GRN}● running${RST}" ;;
    stopped)  label="${DIM}○ stopped${RST}" ;;
    disabled) label="${YLW}  disabled${RST}" ;;
    *)        label="$status" ;;
  esac

  # Truncate description
  [[ ${#desc} -gt 38 ]] && desc="${desc:0:37}…"

  printf "%-22s  " "$id"
  printf "${label}"
  printf "  %-8s  %s\n" "$version" "$desc"

done < <(list_agents_raw)
