<?php
session_start();
header('Content-Type: application/json');
require_once __DIR__ . '/../../db/conexion.php';

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

$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;
}

$sql = "UPDATE PlantillaSolicitMovim SET EstatusRH = 3 WHERE ID = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id);

if ($stmt->execute()) {
  echo json_encode(['success' => true]);
} else {
  echo json_encode(['success' => false, 'message' => 'Error al rechazar']);
}
