Functions/Private/Remove-FileWithLockCheck.ps1

function Remove-FileWithLockCheck {
    <#
    .SYNOPSIS
        Internal helper function to delete files with lock checking.
 
    .DESCRIPTION
        Attempts to delete files, checking for locks first using Test-FileLock and
        reporting any failures. This is an internal function used by Remove-StaleFile.
 
    .PARAMETER FilesToDelete
        Array of FileInfo objects to delete.
 
    .NOTES
        This is a private function and is not exported from the module.
        Uses Test-FileLock -Silent for lock detection.
        Optionally uses OrionDesign module for enhanced output if available.
    #>


    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [System.IO.FileInfo[]]$FilesToDelete
    )

    process {
        foreach ($file in $FilesToDelete) {
            try {
                # Check if file is locked using Test-FileLock
                if (Test-FileLock -FilePath $file.FullName -Silent) {
                    Write-Warning "File is locked and cannot be deleted: $($file.FullName)"
                    continue
                }

                Remove-Item -Path $file.FullName -Force
                
                # Simple left-aligned output
                Write-Host "Deleted: " -NoNewline
                Write-Host "$($file.Name)" -ForegroundColor Green
            }
            catch {
                Write-Warning "Failed to delete $($file.FullName): $_"
            }
        }
    }
}