#Requires -Version 7.4

function Test-WindowsEnvironmentPrerequisite {
    <#
    .SYNOPSIS
        Validates that the session is running in a Windows environment.

    .DESCRIPTION
        Checks if the current PowerShell session is running on Windows, either natively
        or via WSL interop (pwsh.exe called from WSL). This is determined by checking
        if $env:OS equals 'Windows_NT'.

    .EXAMPLE
        Test-WindowsEnvironmentPrerequisite

        Returns a result object indicating whether running in a Windows environment.

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

    # The check: $env:OS should equal 'Windows_NT' for both native Windows and WSL interop
    $isWindowsEnvironment = $env:OS -eq 'Windows_NT'

    # Gather additional environment details for reporting
    $osDescription = [System.Runtime.InteropServices.RuntimeInformation]::OSDescription
    $runtimeIdentifier = [System.Runtime.InteropServices.RuntimeInformation]::RuntimeIdentifier

    # Build current value description
    $currentValue = if ($isWindowsEnvironment) {
        "Windows_NT ($osDescription)"
    }
    else {
        $envOS = $env:OS ?? 'Not Set'
        "$envOS - $osDescription (Runtime: $runtimeIdentifier)"
    }

    $message = if ($isWindowsEnvironment) {
        'Running in Windows environment. Requirement met.'
    }
    else {
        'Not running in a Windows environment. vSEAL must run on Windows (native or via WSL interop with pwsh.exe).'
    }

    [PSCustomObject]@{
        Name     = 'Windows Environment'
        Passed   = $isWindowsEnvironment
        Message  = $message
        Required = 'Windows environment ($env:OS -eq "Windows_NT")'
        Current  = $currentValue
        HelpUrl  = 'https://learn.microsoft.com/en-us/windows/wsl/filesystems#run-windows-tools-from-linux'
    }
}
