functions/public/Get-KlippyJobQueue.ps1

function Get-KlippyJobQueue {
    <#
    .SYNOPSIS
        Gets the print job queue from a Klipper printer.

    .DESCRIPTION
        Retrieves the list of queued print jobs and queue status.

    .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
        Get-KlippyJobQueue
        Gets the job queue from the default printer.

    .EXAMPLE
        Get-KlippyJobQueue -PrinterName "voronv2"
        Gets the job queue from the specified printer.

    .OUTPUTS
        KlippyCLI.JobQueue object.
    #>

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

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

        [Parameter(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

        try {
            $response = Invoke-KlippyJsonRpc -Printer $printer -Method "server/job_queue/status" -NoNormalize

            # Output queue status
            $queueStatus = [PSCustomObject]@{
                PSTypeName  = 'KlippyCLI.JobQueueStatus'
                PrinterId   = $printer.Id
                PrinterName = $printer.PrinterName
                QueueState  = $response.queue_state
                JobCount    = if ($response.queued_jobs) { $response.queued_jobs.Count } else { 0 }
            }

            Write-Output $queueStatus

            # Output individual jobs
            if ($response.queued_jobs) {
                foreach ($job in $response.queued_jobs) {
                    $timeAdded = if ($job.time_added) {
                        [DateTimeOffset]::FromUnixTimeSeconds([long]$job.time_added).LocalDateTime
                    } else { $null }

                    [PSCustomObject]@{
                        PSTypeName  = 'KlippyCLI.QueuedJob'
                        PrinterId   = $printer.Id
                        PrinterName = $printer.PrinterName
                        JobId       = $job.job_id
                        FileName    = $job.filename
                        TimeAdded   = $timeAdded
                    }
                }
            }
        }
        catch {
            Write-Error "Failed to get job queue from '$($printer.PrinterName)': $_"
        }
    }
}