<?php

namespace Datalumo\PhpSdk\DataObjects;

class Entry
{
    public function __construct(
        public readonly string $id,
        public readonly string $collectionId,
        public readonly ?string $title,
        public readonly string $rawText,
        public readonly ?array $meta,
        public readonly ?string $sourceUrl,
        public readonly ?string $sourceType,
        public readonly ?string $sourceId,
        public readonly string $createdAt,
        public readonly string $updatedAt,
    ) {}

    public static function fromArray(array $data): self
    {
        return new self(
            id: $data['id'],
            collectionId: $data['collection_id'],
            title: $data['title'] ?? null,
            rawText: $data['raw_text'],
            meta: $data['meta'] ?? null,
            sourceUrl: $data['source_url'] ?? null,
            sourceType: $data['source_type'] ?? null,
            sourceId: $data['source_id'] ?? null,
            createdAt: $data['created_at'],
            updatedAt: $data['updated_at'],
        );
    }
}
