<?php
/**
 * SAC 2026 - ARCHIVE RETRIEVAL ENGINE v1.0
 * Kernel V4.0.84
 */
require_once 'config.php';

if (!isset($_SESSION['user_id'])) response(["error" => "No autorizado"], 401);

try {
    $stmt = $pdo->query("SELECT * FROM payment_agreements_archive ORDER BY completion_date DESC, id DESC");
    $data = $stmt->fetchAll();
    
    response(["success" => true, "data" => $data]);
} catch (PDOException $e) {
    response(["error" => "Error de acceso al archivo: " . $e->getMessage()], 500);
}
?>