"""EntityNode — nodo de entidad extraido de un knowledge graph."""

from dataclasses import dataclass, field


@dataclass
class EntityNode:
    """Nodo de entidad extraido de un knowledge graph.

    Contiene la identidad, tipo(s), atributos y relaciones de una entidad.
    Generico — no acoplado a Zep o ningun graph DB especifico.
    """

    uuid: str
    name: str
    labels: list[str] = field(default_factory=list)
    summary: str = ""
    attributes: dict = field(default_factory=dict)
    related_edges: list[dict] = field(default_factory=list)
    related_nodes: list[dict] = field(default_factory=list)

    def to_dict(self) -> dict:
        """Serializa el nodo a un diccionario."""
        return {
            "uuid": self.uuid,
            "name": self.name,
            "labels": self.labels,
            "summary": self.summary,
            "attributes": self.attributes,
            "related_edges": self.related_edges,
            "related_nodes": self.related_nodes,
        }

    def get_entity_type(self) -> str | None:
        """Retorna el primer label que no sea generico ("Entity"), o None."""
        for label in self.labels:
            if label != "Entity":
                return label
        return None
