<?php
session_start();
header('Content-Type: application/json');
include '../includes/db_connect.php';

$response = ['status' => 'waiting'];

if (isset($_SESSION['user_id'])) {
    $userId = $_SESSION['user_id'];
    
    $stmt = $conn->prepare("SELECT id FROM devices WHERE user_id = ? AND status = 'active'");
    $stmt->bind_param("i", $userId);
    $stmt->execute();
    $stmt->store_result();
    
    if ($stmt->num_rows > 0) {
        $response['status'] = 'paired';
    }
    $stmt->close();
}

echo json_encode($response);
$conn->close();
?>