from __future__ import annotations

from dataclasses import dataclass, field
from typing import Iterable

from analogai.foundation.modules.fact.fact_source import FactSource


@dataclass(frozen=True)
class SearchResult:
    text: str
    sources: list[object] = field(default_factory=list)

    @property
    def source(self) -> FactSource | None:
        return self.sources[0] if self.sources else None

    @classmethod
    def from_sources(cls, text: str, sources: Iterable[object] | None = None) -> "SearchResult":
        return cls(text=text, sources=list(sources or []))