#!/bin/bash

# Show all network services
port_show_all_network_services()
{
    echo ""
    echo "🌐 Network Services Overview"
    echo "=========================="
    echo ""
    
    local sql="SELECT app_name, service_name, ip_address, internal_port, external_port, service_type, access_type, category, status FROM network_services WHERE status = 'active' ORDER BY category, app_name, service_name;"
    
    echo "📂 Category | 📦 App/Service | 🌐 IP | 🔌 Port | 🏷️ Type | 🔐 Access | 📊 Status"
    echo "---------|---------------|------|--------|----------|-----------|----------"
    
    while IFS='|' read -r app_name service_name ip_address internal_port external_port service_type access_type category status; do
        local port_display="${external_port:-"int"}"
        local status_icon="🟢"
        
        case "$status" in
            "inactive") status_icon="🔴" ;;
            "conflict") status_icon="🟡" ;;
            "migrating") status_icon="🔄" ;;
        esac
        
        printf "%-9s | %-13s | %-4s | %-6s | %-8s | %-9s | %s\n" \
            "${category:-"other"}" "$app_name/$service_name" "${ip_address##*.}" "$port_display" "$service_type" "$access_type" "$status_icon"
    done < <(sqlite3 "$docker_dir/$db_file" "$sql" 2>/dev/null)
    
    echo ""
}
