Modules/businessdev.ALbuild.RuntimePackages/Private/New-BcRuntimeVersionResult.ps1

function New-BcRuntimeVersionResult {
    <#
    .SYNOPSIS
        Wraps one product row for one platform version in the result shape every reporting path expects.
 
    .DESCRIPTION
        Get-BcRuntimeLogSection, ConvertTo-BcRuntimeJUnit, ConvertTo-BcRuntimeSummaryMarkdown and
        ConvertTo-BcRuntimeIssueJUnit all read the same object: a platform version carrying a Products
        list. That shape was built for the factory, where one container held many products; a per-product
        run has exactly one product per platform version, and it keeps the shape anyway.
 
        That is the point. Four reporting paths, the Tests tab and the by-cause report already read it,
        and inventing a second shape for the per-product route would mean either duplicating all four or
        teaching each of them two dialects.
 
    .PARAMETER PlatformVersion
        The platform version this result belongs to.
 
    .PARAMETER Country
        Localisation of the artifact, or ''.
 
    .PARAMETER Row
        The product row: Name, Status, Seconds, Error, File.
 
    .PARAMETER Started
        When work on this platform version began, so the reported duration covers all of it - including
        the artifact fetch and the chain, not just the compile.
 
    .OUTPUTS
        PSCustomObject with PlatformVersion, Country, Status, Seconds, Products.
    #>

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $PlatformVersion,
        [AllowEmptyString()] [string] $Country = '',
        [Parameter(Mandatory)] [ValidateNotNull()] [object] $Row,
        [datetime] $Started = (Get-Date)
    )

    # A skip is not an issue: the aggregate status distinguishes 'nothing was wrong' from 'something was'
    # so the caller can decide the task result without re-deriving it from the rows.
    $status = switch ("$($Row.Status)") {
        'Failed' { 'SucceededWithIssues' }
        default { 'Succeeded' }
    }

    return [PSCustomObject]@{
        PlatformVersion = $PlatformVersion
        Country         = $Country
        Status          = $status
        Seconds         = [Math]::Round(((Get-Date) - $Started).TotalSeconds, 1)
        Products        = @($Row)
    }
}