"""Parser for ``<DocumentVariant>`` elements in HOL DMSContent responses."""
import xml.etree.ElementTree as ET


class DmsContentDocumentVariant:
    """Represents a ``<DocumentVariant>`` element within a HOL ``<Object>``.

    Document variants describe individual versions or renditions of a document,
    including version identifiers and parent-child relationships.
    """

    def __init__(self, node: ET.Element):
        self._node = node

    @property
    def is_active(self) -> bool:
        """``True`` if this variant is the currently active version."""
        return bool(self._node.get("is_active", False))

    @property
    def doc_id(self) -> int:
        """Numeric document ID of this variant."""
        return int(self._node.get("doc_id", -1))

    @property
    def doc_parent(self) -> int:
        """Numeric document ID of the parent variant, or ``-1`` if this is the root."""
        return int(self._node.get("doc_parent", -1))

    @property
    def doc_ver(self) -> str:
        """Version label string of this variant (e.g. ``1.0``, ``2.1``)."""
        return self._node.get("doc_ver", "")

    def variants(self) -> list["DmsContentDocumentVariant"]:
        """Returns all child ``<DocumentVariant>`` elements nested within this variant.

        Returns:
            list[DmsContentDocumentVariant]: Direct child variants, may be empty.
        """
        return [DmsContentDocumentVariant(variant) for variant in self._node.findall("DocumentVariant")]
