<?php
session_start();
header('Content-Type: application/json');

if (!isset($_SESSION['rol']) || !in_array($_SESSION['rol'], ['contabilidad', 'adminTi'])) {
  echo json_encode(['success' => false, 'message' => 'Acceso denegado']);
  exit;
}

require_once(__DIR__ . '/../db/conexion.php');

$data = json_decode(file_get_contents("php://input"), true);
$id = isset($data['id']) ? intval($data['id']) : 0;

if ($id <= 0) {
  echo json_encode(['success' => false, 'message' => 'ID inválido']);
  exit;
}

$update = $conn->prepare("UPDATE PlantillaSolicitMovim SET enteradoContabilidad = 1 WHERE ID = ?");
$update->bind_param("i", $id);

if ($update->execute()) {
  echo json_encode(['success' => true]);
} else {
  echo json_encode(['success' => false, 'message' => 'No se pudo marcar como enterado']);
}
