#Requires -Version 7.4

function Test-PSVersionPrerequisite {
    <#
    .SYNOPSIS
        Validates that PowerShell 7.4 or higher is running.

    .DESCRIPTION
        Checks the current PowerShell version to ensure compatibility with vSEAL.
        The module requires PowerShell 7.4+ for null-conditional (?.) and null-coalescing (??) operators.

    .EXAMPLE
        Test-PSVersionPrerequisite

        Returns a result object indicating whether PowerShell 7.4+ is running.

    .OUTPUTS
        [PSCustomObject] with Name, Passed, Message, Required, Current, and HelpUrl properties.
    #>
    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param()

    $minimumVersion = [version]'7.4'
    $currentVersion = $PSVersionTable.PSVersion
    $passed = $currentVersion -ge $minimumVersion

    $message = if ($passed) {
        "PowerShell $($currentVersion.ToString()) meets minimum requirement."
    }
    else {
        "PowerShell 7.4+ required, found $($currentVersion.ToString()). Install PowerShell 7: https://aka.ms/powershell"
    }

    [PSCustomObject]@{
        Name     = 'PowerShell Version'
        Passed   = $passed
        Message  = $message
        Required = 'PowerShell 7.4 or higher'
        Current  = "PowerShell $($currentVersion.ToString())"
        HelpUrl  = 'https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell'
    }
}
