#!/bin/bash

backupAllApps()
{
    isHeader "Backing up all installed applications"

    if [ ! -f "$docker_dir/$db_file" ]; then
        isError "Database not found: $docker_dir/$db_file"
        return 1
    fi

    local app_names=()
    while IFS= read -r name; do
        app_names+=("$name")
    done < <(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;")

    if [[ ${#app_names[@]} -eq 0 ]]; then
        isNotice "No installed applications found — nothing to back up"
        return 0
    fi

    for name in "${app_names[@]}"; do
        backupAppStart "$name"
    done

    isSuccessful "Backup pass complete — ${#app_names[@]} apps"
}
