<?php
require_once dirname(__DIR__) . '/config.php';

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

$user_id = $_SESSION['user_id'] ?? 0;
$announcement_id = intval($_POST['id'] ?? 0);

if ($user_id <= 0 || $announcement_id <= 0) {
    echo json_encode(['success' => false]);
    exit;
}

// 检查是否已存在
$exists = $db->fetchOne("SELECT id FROM announcement_reads WHERE announcement_id = $announcement_id AND user_id = $user_id");
if (!$exists) {
    $db->query("INSERT INTO announcement_reads (announcement_id, user_id) VALUES ($announcement_id, $user_id)");
}

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