<?php
function executeRemoteCommand($ip, $username, $password, $command, $vmName) {
    if (!$ip || !$username || !$password) {
        return ['success' => false, 'message' => 'RDP connection details missing'];
    }

    try {
        if ($command === 'stop') {
            $result = [
                'success' => true,
                'message' => "Stop command queued for {$vmName} ({$ip})"
            ];
        }
        elseif ($command === 'restart') {
            $result = [
                'success' => true,
                'message' => "Restart command queued for {$vmName} ({$ip})"
            ];
        }
        else {
            $result = [
                'success' => false,
                'message' => 'Invalid command'
            ];
        }
    } catch (Throwable $e) {
        $result = [
            'success' => false,
            'message' => $e->getMessage()
        ];
    }

    return $result;
}
?>
