<?php
include_once 'db_connect.php';

// استقبال البيانات بصيغة JSON
$data = json_decode(file_get_contents("php://input"), true);

if(isset($data['user_id']) && isset($data['onesignal_id'])) {
    
    $user_id = $data['user_id'];
    $os_id = $data['onesignal_id'];

    try {
        // التعديل هنا ليتطابق مع اسم العمود user_id في صورتك
        $sql = "UPDATE doctors SET onesignal_id = :os_id WHERE user_id = :u_id";
        $stmt = $conn->prepare($sql);
        $success = $stmt->execute([
            ':os_id' => $os_id,
            ':u_id'  => $user_id
        ]);

        if($success) {
            echo json_encode(["status" => "success", "message" => "Updated successfully"]);
        } else {
            echo json_encode(["status" => "error", "message" => "Update failed"]);
        }
    } catch (PDOException $e) {
        echo json_encode(["status" => "error", "message" => $e->getMessage()]);
    }
} else {
    echo json_encode(["status" => "error", "message" => "Missing data"]);
}
?>