<?php
/**
 * SAC 2026 - REJECTION ENGINE v1.0
 * Arquitecto: Andres Mathison
 */
require_once 'config.php';

checkAccess(['admin', 'programmer', 'board']);

$data = json_decode(file_get_contents("php://input"), true);

if (!isset($data['feeId']) || !isset($data['propertyId'])) {
    response(["error" => "Faltan parámetros"], 400);
}

$reason = $data['reason'] ?? "Reporte no validado por inconsistencia.";

try {
    $stmt = $pdo->prepare("UPDATE property_debts 
                          SET pending_payment_json = NULL, 
                              rejection_message = ? 
                          WHERE fee_id = ? AND property_id = ?");
    
    $stmt->execute([$reason, $data['feeId'], $data['propertyId']]);

    logSystemAction("RECHAZÓ reporte de pago para unidad ID: " . $data['propertyId'], "PAGOS");
    
    response(["success" => true]);

} catch (PDOException $e) {
    response(["error" => $e->getMessage()], 500);
}
?>