<?php
// public_html/earnapp/api/vm/command/result.php
require_once __DIR__ . '/../../../db.php';
header('Content-Type: application/json');

$data = json_decode(file_get_contents('php://input'), true);
$id = (int)($data['command_id'] ?? 0);
$ok = !empty($data['success']);
$msg = $data['message'] ?? '';

if (!$id) { echo json_encode(['success'=>false]); exit; }

$stmt = $conn->prepare("UPDATE command_logs SET status=?, result_message=? WHERE id=?");
$status = $ok ? 'done' : 'failed';
$stmt->bind_param("ssi", $status, $msg, $id);
$stmt->execute();

echo json_encode(['success'=>true]);
