from typing import Any, Dict

from .report_serializable import ReportSerializable
from .report_title import ReportTitle


def add_param(param: Dict, key: str, value: Any):
    """Adds a key-value pair to a params dict, serializing known types automatically.

    Args:
        param: Target params dict to update.
        key: Parameter name.
        value: Parameter value. ``ReportSerializable`` instances are serialized via
            ``build_content()``, ``ReportTitle`` via ``title_content``. ``None`` is ignored.
    """
    if value is not None:
        if isinstance(value, ReportSerializable):
            param[key] = value.build_content()
        elif isinstance(value, ReportTitle):
            param[key] = value.title_content
        else:
            param[key] = value
