#!/bin/bash

databaseListInstalledApps() 
{
    # Check if sqlite3 is available
    if ! command -v sqlite3 &> /dev/null; then
        isNotice "sqlite3 command not found. Make sure it's installed."
    fi

    # Check if database file is available
    if [ ! -f "$docker_dir/$db_file" ]; then
        isNotice "Database file not found. Make sure it's installed."
    fi

    isHeader "Listing installed apps"

    # Get apps and display them
    local apps=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;")
    
    if [ -n "$apps" ]; then
        echo "$apps" | while IFS="|" read -r app_name; do
            databaseListInstalledApp "$app_name" "no_header"
        done
    else
        isSuccessful "No apps found."
    fi
}
