from typing import Any, Optional


class ReportTitle(object):
    """A report title with optional interpolation params.

    Attributes:
        title_content: Resolved content — plain string when no params, or
            ``{"text": ..., "params": ...}`` when params are set.
    """

    def __init__(self, text: str, params: Optional[Any] = None):
        """Creates a ReportTitle with the given text and optional interpolation params.

        Args:
            text: Title text, may contain interpolation placeholders.
            params: Values to interpolate into the title text.
        """
        self.text = text
        self.params: Optional[Any] = None
        self.update_params(params)

    def update_params(self, params: Optional[Any] = None):
        """Updates interpolation params and rebuilds title_content.

        Args:
            params: New param values. Pass ``None`` to clear params.
        """
        self.params = params
        self._build_content()

    def _build_content(self):
        if self.params is None:
            self.title_content = self.text
        else:
            self.title_content = {
                "text": self.text,
                "params": self.params,
            }
