"""Represents a ``<MultiField>`` element in a DMSContent HOL response."""

import xml.etree.ElementTree as ET


class DmsContentObjectMultiField:
    """Represents a ``<MultiField>`` element within ``<MultiFields>`` in the DMSContent HOL response.

    Each multi-field contains multiple pages, each with a list of string values.
    Use ``pages`` to retrieve the full page-to-values mapping.
    """

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

    @property
    def internal_name(self) -> str:
        """Internal name of the multi-value field."""
        return self._node.get("internal_name", "")

    @property
    def name(self) -> str:
        """Display name of the multi-value field."""
        return self._node.get("name", "")

    @property
    def dbname(self) -> str:
        """Database column name of the multi-value field."""
        return self._node.get("dbname", "")

    @property
    def pages(self) -> dict[int, list[str]]:
        """Returns a mapping of page ID to list of raw string values.

        Returns:
            dict[int, list[str]]: Page ID → list of value strings.
        """
        result: dict[int, list[str]] = {}
        for page_node in self._node.findall("Page"):
            page_id = int(page_node.get("id", "-1"))
            result[page_id] = [v.text or "" for v in page_node.findall("Value")]
        return result
