<?php
$device_id = $_GET['device_id'] ?? null;

if ($device_id) {
    $dataFile = "device_data.json"; 
    $devices = json_decode(file_get_contents($dataFile), true);

    $device = null;
    foreach ($devices as $d) {
        if ($d['device_id'] === $device_id) {
            $device = $d;
            break;
        }
    }

    if ($device) {
        echo json_encode([
            'success' => true,
            'device_id' => $device['device_id'],
            'device_model' => $device['device_model'],
            'status' => $device['status'],
            'last_active' => $device['last_active'],
            'os' => $device['os']
        ]);
    } else {
        echo json_encode(['success' => false]);
    }
} else {
    echo json_encode(['success' => false]);
}
?>
