functions/public/Resume-KlippyPrint.ps1

function Resume-KlippyPrint {
    <#
    .SYNOPSIS
        Resumes a paused print job on a Klipper printer.

    .DESCRIPTION
        Resumes a previously paused print job.

    .PARAMETER Id
        The unique identifier of the printer.

    .PARAMETER PrinterName
        The friendly name of the printer.

    .PARAMETER InputObject
        A printer object from pipeline input.

    .PARAMETER Wait
        Wait for the print to resume before returning.

    .EXAMPLE
        Resume-KlippyPrint
        Resumes the print on the default printer.

    .EXAMPLE
        Resume-KlippyPrint -PrinterName "voronv2" -Wait
        Resumes the print and waits for it to be printing.

    .OUTPUTS
        PSCustomObject with resume 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,

        [Parameter()]
        [switch]$Wait
    )

    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 'paused') {
                Write-Warning "[$($printer.PrinterName)] Printer is not paused (state: $($status.State))"
                return [PSCustomObject]@{
                    PSTypeName  = 'KlippyCLI.PrintJob'
                    PrinterId   = $printer.Id
                    PrinterName = $printer.PrinterName
                    Action      = 'ResumeSkipped'
                    State       = $status.State
                    Success     = $false
                    Message     = "Printer is not paused"
                }
            }
        }
        catch {
            Write-Verbose "Could not check current state: $_"
        }

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

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

                $result = [PSCustomObject]@{
                    PSTypeName  = 'KlippyCLI.PrintJob'
                    PrinterId   = $printer.Id
                    PrinterName = $printer.PrinterName
                    Action      = 'Resumed'
                    Success     = $true
                }

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

                if ($Wait) {
                    $waitResult = Wait-KlippyPrintStarted -PrinterName $printer.PrinterName -Timeout 60
                    $result | Add-Member -NotePropertyName 'State' -NotePropertyValue $waitResult.State -Force
                }

                return $result
            }
            catch {
                Write-Error "[$($printer.PrinterName)] Failed to resume print: $_"

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