#!/bin/bash

checkAppNetworkCompatibility()
{
    local target_subnet="$1"
    local target_base="${target_subnet%/*}"
    
    # Get list of installed apps
    local installed_apps=$(getInstalledApps)
    
    if [[ -z "$installed_apps" ]]; then
        :
    fi
    
    local incompatible_apps=0
    
    for app_name in $installed_apps; do
        local compose_file="$containers_dir/$app_name/compose.yml"
        
        if [[ -f "$compose_file" ]]; then
            # Check for static IP assignments that might be incompatible
            local static_ips=$(grep -E "ipv4_addresses:|ip:" "$compose_file" 2>/dev/null)
            
            if [[ -n "$static_ips" ]]; then
                # Check if any IPs are outside the target subnet range
                while read -r ip_line; do
                    local ip=$(echo "$ip_line" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -1)
                    if [[ -n "$ip" && ! "$ip" =~ ^${target_base%.*} ]]; then
                        isNotice "  $app_name has incompatible IP: $ip (target: $target_base.0/24)"
                        ((incompatible_apps++))
                    fi
                done <<< "$static_ips"
            fi
        fi
    done
    
    if [[ $incompatible_apps -gt 0 ]]; then
        isNotice "Found $incompatible_apps apps with network settings that may need updating"
    else
        :
    fi
}
