#Requires -Version 7.4

function Format-PluginSummaryTable {
    <#
    .SYNOPSIS
    DEPRECATED: No longer called by Invoke-vSEAL. Retained for backward compatibility.
    Plugin summary is now emitted as a plugin.summary structured event.

    .DESCRIPTION
    Produces a formatted string array displaying each plugin's priority, name, enabled
    status, and applicability. Plugins are sorted by priority. When a plugin is not
    applicable, the skip reason is appended to its row. The table uses Unicode box-drawing
    characters for the separator line.

    .PARAMETER Plugins
    Array of plugin objects to display. Each object must have Priority, Name, Enabled,
    Applicable, and optionally Reason properties.

    .PARAMETER Phase
    The current execution phase name, displayed in the table header. Defaults to 'Unknown'.
    #>
    [CmdletBinding()]
    [OutputType([string[]])]
    param(
        [Parameter(Mandatory)]
        [array]$Plugins,

        [string]$Phase = 'Unknown'
    )

    $output = @()

    # Header
    $output += "=== Plugin Summary ($Phase Phase) ==="
    $output += "  Priority  Plugin                   Enabled  Applies"
    $output += "  " + [string]::new([char]0x2500, 53)  # Unicode box drawing light horizontal

    # Sort by priority and format each row
    $sorted = $Plugins | Sort-Object { $_.Priority }

    foreach ($p in $sorted) {
        $enabledStr = if ($p.Enabled) { 'yes' } else { 'no' }
        $appliesStr = if ($p.Applicable) { 'yes' } else { 'no' }

        # Format the base row
        $row = "  {0,-8}  {1,-24} {2,-8} {3}" -f $p.Priority, $p.Name, $enabledStr, $appliesStr

        # Add reason if not applicable
        if (-not $p.Applicable -and $p.Reason) {
            $row += "  ($($p.Reason))"
        }

        $output += $row
    }

    return $output
}
