<?php

namespace App\Tests\Settlement;

use App\Settlement\Entity\WalletTransaction;
use App\Tests\ApiTestCase;

/**
 * GET /wallet/transactions must page rather than return an unbounded list, and
 * expose totals in meta without breaking the existing data.data envelope.
 */
class WalletTransactionsPaginationTest extends ApiTestCase
{
    public function testPaginatesAndReportsTotals(): void
    {
        $user = $this->createUser();
        for ($i = 0; $i < 7; $i++) {
            $this->em->persist(new WalletTransaction($user, 1000, 'credit', 1000));
        }
        $this->em->flush();

        $body = $this->authJson('GET', '/api/v1/wallet/transactions?limit=5', $user);
        $this->assertSame(200, $this->responseCode());
        $this->assertCount(5, $body['data']['data']);
        $this->assertSame(7, $body['data']['meta']['totalRecords']);
        $this->assertSame(2, $body['data']['meta']['totalPages']);

        $page2 = $this->authJson('GET', '/api/v1/wallet/transactions?limit=5&page=2', $user);
        $this->assertCount(2, $page2['data']['data']);
    }
}
