#!/bin/bash

dockerPruneAppNetworks() 
{
    if [[ $CFG_REQUIREMENT_DOCKER_NETWORK_PRUNE == "true" ]]; then
        local app_name="$1"
        if [ ! -z "$app_name" ]; then
            local networks_found=false
            # Prune all networks except those containing the specified app_name
            for network_id in $(runFileOp docker network ls --quiet); do
                network_name=$(runFileOp docker network inspect --format '{{.Name}}' "$network_id")
                if [[ "$network_name" == *"$app_name"* ]]; then
                    local result=$(dockerCommandRun "docker network rm "$network_id"")
                    checkSuccess "Removing the unused runFileOp docker network - $network_name"
                    networks_found=true
                fi
            done
            
            if [ "$networks_found" = false ]; then
                isSuccessful "No unused networks found for $app_name"
            fi
        fi
    fi
}
