<?php
require_once dirname(__DIR__) . '/_bootstrap.php';
require_once dirname(__DIR__, 2) . '/common/scanner_service.php';

golder_require_method('POST');
$ctx = golder_api_auth('desktop_sync');
$master = $ctx['master'];
golder_ensure_scanner_table($master);

$input = golder_api_input();
$deviceId = (int)($input['device_id'] ?? 0);

if ($deviceId <= 0) {
    golder_json_response(['status' => 'error', 'message' => 'Cihaz seçilmedi.'], 400);
}

$reqId = golder_uuid4();
$expiresAt = gmdate('Y-m-d H:i:s', time() + 120); // 2 dakika geçerli

$st = $master->prepare("INSERT INTO remote_scan_requests (id, customer_id, target_device_id, status, expires_at) VALUES (?, ?, ?, 'pending', ?)");
$st->execute([$reqId, $ctx['customer_id'], $deviceId, $expiresAt]);

golder_json_response(['status' => 'ok', 'request_id' => $reqId]);


