functions/public/Suspend-KlippyPrint.ps1

function Suspend-KlippyPrint {
    <#
    .SYNOPSIS
        Suspends (pauses) the current print job on a Klipper printer.

    .DESCRIPTION
        Sends a pause command to the printer. The print can be resumed later
        using Resume-KlippyPrint.

    .PARAMETER Id
        The unique identifier of the printer.

    .PARAMETER PrinterName
        The friendly name of the printer.

    .PARAMETER InputObject
        A printer object from pipeline input.

    .EXAMPLE
        Suspend-KlippyPrint
        Suspends the print on the default printer.

    .EXAMPLE
        Suspend-KlippyPrint -PrinterName "voronv2"
        Suspends the print on the specified printer.

    .EXAMPLE
        Get-KlippyPrinter | Where-Object { (Get-KlippyStatus -Id $_.Id).State -eq 'printing' } | Suspend-KlippyPrint
        Suspends all currently printing printers.

    .OUTPUTS
        PSCustomObject with suspend result.
    #>

    [CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = 'Default')]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory = $true, ParameterSetName = 'ById')]
        [ValidateNotNullOrEmpty()]
        [string]$Id,

        [Parameter(Mandatory = $true, ParameterSetName = 'ByName', Position = 0)]
        [ValidateNotNullOrEmpty()]
        [string]$PrinterName,

        [Parameter(Mandatory = $true, ParameterSetName = 'ByObject', ValueFromPipeline = $true)]
        [PSCustomObject]$InputObject
    )

    process {
        # Resolve printer
        $resolveParams = @{}
        switch ($PSCmdlet.ParameterSetName) {
            'ById' { $resolveParams['Id'] = $Id }
            'ByName' { $resolveParams['PrinterName'] = $PrinterName }
            'ByObject' { $resolveParams['InputObject'] = $InputObject }
        }

        $printer = Resolve-KlippyPrinterTarget @resolveParams

        # Check current state
        try {
            $status = Get-KlippyStatus -PrinterName $printer.PrinterName
            if ($status.State -ne 'printing') {
                Write-Warning "[$($printer.PrinterName)] Printer is not currently printing (state: $($status.State))"
                return [PSCustomObject]@{
                    PSTypeName  = 'KlippyCLI.PrintJob'
                    PrinterId   = $printer.Id
                    PrinterName = $printer.PrinterName
                    Action      = 'SuspendSkipped'
                    State       = $status.State
                    Success     = $false
                    Message     = "Printer is not printing"
                }
            }
        }
        catch {
            Write-Verbose "Could not check current state: $_"
        }

        if ($PSCmdlet.ShouldProcess($printer.PrinterName, "Suspend print")) {
            try {
                Write-Verbose "[$($printer.PrinterName)] Suspending print..."

                $null = Invoke-KlippyJsonRpc -Printer $printer -Method "printer/print/pause"

                Write-Verbose "[$($printer.PrinterName)] Print suspended"

                return [PSCustomObject]@{
                    PSTypeName  = 'KlippyCLI.PrintJob'
                    PrinterId   = $printer.Id
                    PrinterName = $printer.PrinterName
                    Action      = 'Suspended'
                    Success     = $true
                }
            }
            catch {
                Write-Error "[$($printer.PrinterName)] Failed to suspend print: $_"

                return [PSCustomObject]@{
                    PSTypeName  = 'KlippyCLI.PrintJob'
                    PrinterId   = $printer.Id
                    PrinterName = $printer.PrinterName
                    Action      = 'SuspendFailed'
                    Success     = $false
                    Error       = $_.Exception.Message
                }
            }
        }
    }
}