# Module: Installer Utilities
# Purpose: Helper functions for installer creation (metrics, size calculation, etc.)
# Dependencies: None (standalone utilities)

# Count created installers from results
export def count_created_installers [creation_results: list] {
    let shell_count = (
        $creation_results
        | where phase == "shell"
        | first
        | if $in == null { 0 } else { $in.result.installers_created? // 0 }
    )

    let package_count = (
        $creation_results
        | where phase == "package"
        | first
        | if $in == null { 0 } else { $in.result.installers_created? // 0 }
    )

    let gui_count = (
        $creation_results
        | where phase == "gui"
        | first
        | if $in == null { 0 } else { $in.result.installers_created? // 0 }
    )

    let uninstall_count = (
        $creation_results
        | where phase == "uninstall"
        | first
        | if $in == null { 0 } else { $in.result.uninstallers_created? // 0 }
    )

    return ($shell_count + $package_count + $gui_count + $uninstall_count)
}

# Get directory size helper
export def get_directory_size [dir: string] {
    if not ($dir | path exists) {
        return 0
    }

    glob $"($dir)/**/*"
        | each {|file| stat $file | get size }
        | math sum
}
