<?php
header('Content-Type: application/json; charset=UTF-8');
$id = $_POST['id'] ?? null;
if (!$id) { echo json_encode(['success' => false]); exit; }

try {
    $pdo = new PDO("mysql:host=localhost;dbname=CORREOS;charset=utf8mb4", 'root', 'root', [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
    ]);

    $stmt = $pdo->prepare("UPDATE NOTIFICACION SET LEIDO = 'S' WHERE ID_CORREO = ?");
    $stmt->execute([$id]);

    $stmt2 = $pdo->prepare("UPDATE CORREO SET ES_NUEVO = 'N' WHERE ID_CORREO = ?");
    $stmt2->execute([$id]);

    echo json_encode(['success' => true]);
} catch (PDOException $e) {
    echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
