Private/New-Finding.ps1

# New-Finding.ps1
# Constructs a structured finding object for the Findings array.
# Part of the M365-QuickAssess module -- not exported.

function New-Finding
{
    param
    (
        [string]$Type,
        [string]$Summary,
        [string]$Category       = "General",
        [string]$Severity       = "Info",
        [array]$Details,
        [string]$Impact         = "",
        [string]$Recommendation = ""
    )

    $findingList = @()

    if ( $Details -and $Details.Count )
    {
        foreach ( $d in $Details )
        {
            if ( $d -is [string] )
            {
                $detailText = $d
            }
            else
            {
                $detailText = ( $d | ConvertTo-Json -Compress )
            }

            $findingList += [PSCustomObject]@{
                Detail         = $detailText
                Impact         = $Impact
                Recommendation = $Recommendation
            }
        }
    }
    else
    {
        $findingList += [PSCustomObject]@{
            Detail         = $Summary
            Impact         = $Impact
            Recommendation = $Recommendation
        }
    }

    return [PSCustomObject]@{
        Type     = $Type
        Summary  = $Summary
        Category = $Category
        Severity = $Severity
        Findings = @( $findingList )
    }
}