#!/bin/bash
# Consultas CLI a la API de Felix (provisioning)
# Uso: ./check_felix.sh <red> <accion>
# Redes: puebla, capellades, cat
# Acciones: clientes, paquetes, buscar <texto>

DIR="$(dirname "$0")"

TOKEN_PUEBLA="YmFkOTc5YWNjZTA0NTFiMmJmYTBmZDViZjIwM2RjY2Y6"
URL_PUEBLA="https://fiberpuebla-flx1.alea-soluciones.com:9199/fiberpuebla"

TOKEN_CAPELLADES="NGMxMTY3N2ZlYzI2YjczYjUxMDQ1NTJiOTZkZTMwNDY6"
URL_CAPELLADES="https://cap-flx1.alea-soluciones.com:9199/cap"

TOKEN_CAT="Q2FwZWxsYVRlbHZlbnQ6"
URL_CAT="https://cat-flx1.alea-soluciones.com:9199/cat"

case "${1:-puebla}" in
  puebla)  TOKEN=$TOKEN_PUEBLA; URL=$URL_PUEBLA; RED="Puebla";;
  capellades) TOKEN=$TOKEN_CAPELLADES; URL=$URL_CAPELLADES; RED="Capellades";;
  cat)     TOKEN=$TOKEN_CAT; URL=$URL_CAT; RED="CAT";;
  *)       echo "Redes: puebla, capellades, cat"; exit 1;;
esac

case "${2:-clientes}" in
  clientes)
    echo "=== Clientes $RED ==="
    curl -s -k -H "authorization: Basic $TOKEN" -H "cache-control: no-cache" \
      "$URL/customer_technical_info_report" | python3 "$DIR/clientes.py" | head -50
    ;;
  paquetes)
    echo "=== Paquetes $RED ==="
    curl -s -k -H "authorization: Basic $TOKEN" -H "cache-control: no-cache" \
      "$URL/product_package_group" | python3 "$DIR/paquetes.py" | head -50
    ;;
  buscar)
    if [ -z "$3" ]; then echo "Uso: $0 $1 buscar <texto>"; exit 1; fi
    echo "=== Buscando '$3' en $RED ==="
    curl -s -k -H "authorization: Basic $TOKEN" -H "cache-control: no-cache" \
      "$URL/customer_technical_info_report" | python3 "$DIR/buscar.py" "$3"
    ;;
  *)
    echo "Acciones: clientes, paquetes, buscar <texto>"
    exit 1
    ;;
esac
