<?php

use Datalumo\PhpSdk\DataObjects\SearchResult;

it('creates a search result with summarisable flag', function () {
    $result = SearchResult::fromArray([
        'data' => [['name' => 'Item 1']],
        'meta' => [
            'current_page' => 1,
            'last_page' => 1,
            'per_page' => 15,
            'total' => 1,
        ],
        'summarisable' => true,
    ], fn ($item) => $item['name']);

    expect($result)
        ->data->toBe(['Item 1'])
        ->summarisable->toBeTrue();
});

it('handles missing summarisable flag', function () {
    $result = SearchResult::fromArray([
        'data' => [],
        'meta' => [
            'current_page' => 1,
            'last_page' => 1,
            'per_page' => 15,
            'total' => 0,
        ],
    ], fn ($item) => $item);

    expect($result->summarisable)->toBeNull();
});
