<?php
require_once '../../core/bootstrap.php';

// Ensure user is logged in
if (!isset($_SESSION['user_id'])) {
    http_response_code(401);
    exit();
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $data = json_decode(file_get_contents('php://input'), true);
    
    if ($data && isset($data['endpoint'])) {
        $userModel = new User();
        if ($userModel->savePushSubscription($_SESSION['user_id'], $data)) {
            http_response_code(200);
            echo json_encode(['status' => 'success']);
            exit;
        }
    }
}

http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Invalid request']);
?>