<?php
// siigo/scripts/siigo_gastos.php

require_once __DIR__ . '/../config/config.php';
require_once __DIR__ . '/../lib/Client.php';

header('Content-Type: application/json; charset=utf-8');

$client = new SiigoClient();

try {
    // Trae un solo gasto (purchase) para que veas la estructura del JSON
    $response = $client->get('purchases', [
        'page'       => 1,
        'page_size'  => 1,
        'order_by'   => 'date desc'
    ]);

    // Imprime el JSON crudo
    echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
} catch (\Exception $e) {
    http_response_code(500);
    echo json_encode([
        'error' => $e->getMessage()
    ], JSON_UNESCAPED_UNICODE);
}
