<?php
declare(strict_types=1);

require_once dirname(__DIR__) . '/_bootstrap.php';

golder_require_method('POST');
$ctx = golder_api_auth('desktop_sync');
$input = golder_api_input();

$deviceId = (int)($input['device_id'] ?? 0);
$deviceName = trim((string)($input['device_name'] ?? ''));
if ($deviceId <= 0 || $deviceName === '') {
    golder_json_response(['status' => 'error', 'message' => 'device_id and device_name are required'], 400);
}

$ok = golder_rename_device($ctx['master'], (int)$ctx['customer_id'], $deviceId, $deviceName);
if (!$ok) {
    golder_json_response(['status' => 'error', 'message' => 'Device not found or update failed'], 404);
}

golder_json_response(['status' => 'ok']);


