<?php

use Datalumo\PhpSdk\DataObjects\PaginatedResponse;

it('creates a paginated response from array', function () {
    $response = PaginatedResponse::fromArray([
        'data' => [
            ['name' => 'Item 1'],
            ['name' => 'Item 2'],
        ],
        'meta' => [
            'current_page' => 1,
            'last_page' => 3,
            'per_page' => 15,
            'total' => 45,
        ],
    ], fn (array $item) => $item['name']);

    expect($response)
        ->data->toBe(['Item 1', 'Item 2'])
        ->currentPage->toBe(1)
        ->lastPage->toBe(3)
        ->perPage->toBe(15)
        ->total->toBe(45);
});

it('detects when there are more pages', function () {
    $response = PaginatedResponse::fromArray([
        'data' => [],
        'meta' => [
            'current_page' => 1,
            'last_page' => 3,
            'per_page' => 15,
            'total' => 45,
        ],
    ], fn ($item) => $item);

    expect($response->hasMorePages())->toBeTrue();
});

it('detects when on the last page', function () {
    $response = PaginatedResponse::fromArray([
        'data' => [],
        'meta' => [
            'current_page' => 3,
            'last_page' => 3,
            'per_page' => 15,
            'total' => 45,
        ],
    ], fn ($item) => $item);

    expect($response->hasMorePages())->toBeFalse();
});
