<?php

use App\Models\AddressCollection;
use Illuminate\Contracts\Console\Kernel;

require __DIR__.'/../../vendor/autoload.php';

$app = require __DIR__.'/../../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();

$rows = AddressCollection::with(['address.invoice', 'asset'])
    ->latest('id')
    ->limit(25)
    ->get()
    ->map(fn ($collection) => [
        'id' => $collection->public_id,
        'status' => $collection->status,
        'invoice_id' => $collection->address?->invoice?->public_id,
        'from_address' => $collection->address?->address,
        'asset_code' => $collection->asset?->code,
        'requested_amount_atomic' => (string) $collection->requested_amount_atomic,
        'collected_amount_atomic' => (string) $collection->collected_amount_atomic,
        'provider_reference' => $collection->provider_reference,
        'tx_hash' => $collection->tx_hash,
        'failure_reason' => $collection->failure_reason,
        'created_at' => $collection->created_at?->utc()->toIso8601String(),
    ]);

echo json_encode($rows, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).PHP_EOL;
