<?php
require_once '../db.php';

$device_id = $_GET['device_id'] ?? '';

if ($device_id === '') {
    echo json_encode(['success' => false, 'message' => 'Missing device_id']);
    exit;
}

try {
    $stmt = $pdo->prepare("SELECT * FROM users WHERE device_id = ? LIMIT 1");
    $stmt->execute([$device_id]);
    $user = $stmt->fetch(PDO::FETCH_ASSOC);

    echo json_encode(['success' => true, 'user' => $user]);
} catch (Exception $e) {
    echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
?>
