$metadata */ public function __construct( public readonly string $id, public readonly string $type, public readonly string $title, public readonly string $description, public readonly string $url, public readonly string $icon, public readonly array $metadata = [], ) {} /** * @param array $data */ public static function fromArray(array $data): self { return new self( id: (string) ($data['id'] ?? uniqid('search_', true)), type: (string) ($data['type'] ?? 'unknown'), title: (string) ($data['title'] ?? ''), description: (string) ($data['description'] ?? $data['subtitle'] ?? ''), url: (string) ($data['url'] ?? '#'), icon: (string) ($data['icon'] ?? 'document'), metadata: (array) ($data['metadata'] ?? $data['meta'] ?? []), ); } /** * @return array */ public function toArray(): array { return [ 'id' => $this->id, 'type' => $this->type, 'title' => $this->title, 'description' => $this->description, 'subtitle' => $this->description, 'url' => $this->url, 'icon' => $this->icon, 'metadata' => $this->metadata, 'meta' => $this->metadata, ]; } /** * @return array */ public function jsonSerialize(): array { return $this->toArray(); } }