Private/New-WUHealthIssue.ps1

function New-WUHealthIssue {
    <#
    .SYNOPSIS
        Creates a standardized Windows Update health issue object.
 
    .DESCRIPTION
        Helper function to create consistent issue objects used throughout the
        WindowsUpdateTools module for reporting problems and tracking remediation.
 
    .PARAMETER Type
        Category of the issue (e.g., Services, ComponentStore, SetupDiag, etc.)
 
    .PARAMETER Severity
        Severity level of the issue. Valid values: Critical, Warning, Info
 
    .PARAMETER Description
        Human-readable description of the issue.
 
    .PARAMETER Details
        Optional hashtable with additional details about the issue.
 
    .PARAMETER Remediation
        Optional suggested remediation action.
 
    .EXAMPLE
        $issue = New-WUHealthIssue -Type "Services" -Severity "Critical" -Description "Windows Update service not running"
 
    .EXAMPLE
        $issue = New-WUHealthIssue -Type "ComponentStore" -Severity "Warning" -Description "Potential corruption detected" -Remediation "Run DISM RestoreHealth"
 
    .NOTES
        This is a private function used internally by the WindowsUpdateTools module.
        Returns a PSCustomObject with standardized properties for consistent issue tracking.
    #>


    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$Type,

        [Parameter(Mandatory = $true)]
        [ValidateSet('Critical', 'Warning', 'Info')]
        [string]$Severity,

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$Description,

        [hashtable]$Details,

        [string]$Remediation
    )

    # Create standardized issue object
    $issue = [PSCustomObject]@{
        Type = $Type
        Severity = $Severity
        Description = $Description
        Details = if ($Details) { $Details } else { @{} }
        Remediation = $Remediation
        Timestamp = Get-Date
        Id = [System.Guid]::NewGuid().ToString('N').Substring(0, 8)  # Short unique identifier
    }

    # Add type name for better object identification
    $issue.PSObject.TypeNames.Insert(0, 'WindowsUpdateTools.HealthIssue')

    return $issue
}