"""Parser for top-level ``<Field>`` elements within a DMSContent ``<Object>``."""
from ecmind_blue_client.ecm.parser._dms_content_object_field_base import (
    DmsContentObjectFieldBase,
)


class DmsContentObjectField(DmsContentObjectFieldBase):
    """Represents a ``<Field>`` element within a HOL ``<Object>``.

    The raw value is stored as the ``value`` attribute when present, otherwise as
    the element text content. The display value is always the element text.
    """

    def _getRawValue(self) -> str | None:
        """Returns the ``value`` attribute of the ``<Field>`` element, or its text content."""
        return self._node.attrib["value"] if "value" in self._node.attrib else self._node.text

    @property
    def display_value(self) -> str:
        """Human-readable display value (text content of the ``<Field>`` element)."""
        return self._node.text or ""

    @property
    def system(self) -> bool:
        """``True`` if this is a system-managed field (not editable by users)."""
        return bool(self._node.get("system", False))

    @property
    def displayname(self) -> str:
        """Optional display name override for this field, if provided by the server."""
        return self._node.get("displayname", "")
