<?php

use Datalumo\PhpSdk\DataObjects\Entry;
use Datalumo\PhpSdk\DataObjects\SummaryResponse;

it('creates a summary response from array', function () {
    $response = SummaryResponse::fromArray([
        'summary' => 'This is a summary.',
        'references' => [['title' => 'Ref 1']],
        'data' => [
            [
                'id' => 'entry-1',
                'collection_id' => 'col-1',
                'raw_text' => 'Content',
                'created_at' => '2026-01-01T00:00:00Z',
                'updated_at' => '2026-01-02T00:00:00Z',
            ],
        ],
        'has_relevant_results' => true,
    ]);

    expect($response)
        ->summary->toBe('This is a summary.')
        ->references->toBe([['title' => 'Ref 1']])
        ->hasRelevantResults->toBeTrue()
        ->data->toHaveCount(1);

    expect($response->data[0])->toBeInstanceOf(Entry::class);
});

it('handles missing optional fields', function () {
    $response = SummaryResponse::fromArray([
        'summary' => 'Summary text',
        'references' => [],
    ]);

    expect($response)
        ->data->toBe([])
        ->hasRelevantResults->toBeNull();
});
