functions/public/Restart-KlippyHost.ps1

function Restart-KlippyHost {
    <#
    .SYNOPSIS
        Reboots the Klipper host machine.

    .DESCRIPTION
        Reboots the host machine running Klipper/Moonraker.
        This is a system-level reboot and will disconnect the printer temporarily.

    .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 Force
        Skip confirmation prompt.

    .EXAMPLE
        Restart-KlippyHost
        Reboots the default printer's host (with confirmation).

    .EXAMPLE
        Restart-KlippyHost -PrinterName "voronv2" -Force
        Reboots without confirmation.

    .NOTES
        The printer will be unavailable during the reboot process.

    .OUTPUTS
        None.
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
    param(
        [Parameter(ParameterSetName = 'ById')]
        [ValidateNotNullOrEmpty()]
        [string]$Id,

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

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

        [Parameter()]
        [switch]$Force
    )

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

        $printer = Resolve-KlippyPrinterTarget @resolveParams

        if ($Force -or $PSCmdlet.ShouldProcess($printer.PrinterName, "Reboot Host Machine")) {
            try {
                Write-Warning "Rebooting host machine for '$($printer.PrinterName)'..."
                $null = Invoke-KlippyJsonRpc -Printer $printer -Method "machine/reboot"
                Write-Host "Reboot command sent. The printer will be temporarily unavailable." -ForegroundColor Yellow
            }
            catch {
                Write-Error "Failed to reboot host for '$($printer.PrinterName)': $_"
            }
        }
    }
}