# reference: https://learn.microsoft.com/zh-cn/powershell/scripting/samples/changing-computer-state?view=powershell-7.3
# shellcheck shell=dash
___x_cmd_pwsh_computer(){
    [ $# -gt 0 ] || set -- --help

    local op="$1";  shift
    case "$op" in
        stop|restart|lock|logoff)
            "___x_cmd_pwsh_computer_${op}" "$@"
            ;;
        -h|--help)
            ___x_cmd help -m pwsh computer
            ;;
        *)
            pwsh:error "unsupport op ==> $op"
            ;;
    esac
}

___x_cmd_pwsh_computer_stop(){
    ___x_cmd_pwsh___confirmx "Stop-Computer"
}

___x_cmd_pwsh_computer_lock(){
    ___x_cmd_pwsh___confirmx "rundll32.exe user32.dll,LockWorkStation"
}

___x_cmd_pwsh_computer_logoff(){
    ___x_cmd_pwsh___confirmx logoff
}

___x_cmd_pwsh_computer_restart(){
    local force=
    [ "$1" != --force ] || force=1
    if [ -z "$force" ]; then
        ___x_cmd_pwsh___confirmx Restart-Computer
    else
        ___x_cmd_pwsh___confirmx "Restart-Computer -Force"
    fi
}
