<?php

use Datalumo\PhpSdk\DataObjects\Entry;

it('creates an entry from array', function () {
    $entry = Entry::fromArray([
        'id' => 'entry-123',
        'collection_id' => 'col-456',
        'title' => 'Test Entry',
        'raw_text' => 'Some content here',
        'meta' => ['key' => 'value'],
        'source_url' => 'https://example.com/page',
        'source_type' => 'articles',
        'source_id' => '42',
        'created_at' => '2026-01-01T00:00:00Z',
        'updated_at' => '2026-01-02T00:00:00Z',
    ]);

    expect($entry)
        ->id->toBe('entry-123')
        ->collectionId->toBe('col-456')
        ->title->toBe('Test Entry')
        ->rawText->toBe('Some content here')
        ->meta->toBe(['key' => 'value'])
        ->sourceUrl->toBe('https://example.com/page')
        ->sourceType->toBe('articles')
        ->sourceId->toBe('42')
        ->createdAt->toBe('2026-01-01T00:00:00Z')
        ->updatedAt->toBe('2026-01-02T00:00:00Z');
});

it('handles nullable fields', function () {
    $entry = Entry::fromArray([
        'id' => 'entry-123',
        'collection_id' => 'col-456',
        'raw_text' => 'Content',
        'created_at' => '2026-01-01T00:00:00Z',
        'updated_at' => '2026-01-02T00:00:00Z',
    ]);

    expect($entry)
        ->title->toBeNull()
        ->meta->toBeNull()
        ->sourceUrl->toBeNull()
        ->sourceType->toBeNull()
        ->sourceId->toBeNull();
});
