<?php
// ajax/mark_notification_read.php
session_start();
require_once '../../config/database.php';

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

if(!isset($_SESSION['customer_id']) || !isset($_POST['id'])) {
    echo json_encode(['success' => false]);
    exit;
}

$database = new Database();
$db = $database->getConnection();

$query = "UPDATE notifications SET is_read = 1, read_at = NOW() 
          WHERE id = :id AND customer_id = :customer_id";
$stmt = $db->prepare($query);
$success = $stmt->execute([
    ':id' => $_POST['id'],
    ':customer_id' => $_SESSION['customer_id']
]);

echo json_encode(['success' => $success]);
?>