#Requires -Version 7.4

function Get-vSEALFreeDiskSpace {
    <#
    .SYNOPSIS
        Gets free disk space in MB.

    .DESCRIPTION
        Returns the available free space on the specified drive in megabytes.
        Defaults to the system drive if no drive is specified.

    .PARAMETER Drive
        The drive to check. Defaults to the system drive. Must be an accessible
        drive with media present.

    .OUTPUTS
        [double] Free space in MB.
    #>
    [CmdletBinding()]
    [OutputType([double])]
    param(
        [ValidateScript({
            if (-not $_.TotalSize) {
                throw "Drive does not exist or has no media: $_"
            }
            $true
        })]
        [System.IO.DriveInfo]$Drive = [System.IO.Path]::GetPathRoot([Environment]::SystemDirectory)
    )

    Write-vSEALLog "Checking free disk space on [$Drive]..." -Level VERBOSE
    $freeSpace = [Math]::Round($Drive.AvailableFreeSpace / 1MB)
    Write-vSEALLog "Free disk space on [$Drive]: $freeSpace MB" -Level VERBOSE

    return $freeSpace
}
