<?php
/**
 * API: Check for Order Updates
 */

require_once 'config.php';
checkCaptainAuth();

header('Content-Type: application/json');

$captain_id = $_SESSION['captain_id'];
$last_update = isset($_GET['last_update']) ? $_GET['last_update'] : date('Y-m-d H:i:s', strtotime('-1 minute'));

// التحقق من وجود تحديثات
$sql = "SELECT COUNT(*) as updates 
        FROM orders 
        WHERE captain_id = '$captain_id' 
        AND updated_at > '$last_update'";

$result = $conn->query($sql);
$updates = $result->fetch_assoc()['updates'];

echo json_encode([
    'success' => true,
    'updated' => $updates > 0,
    'server_time' => date('Y-m-d H:i:s')
]);
?>