from typing import Dict
from typing import Any
from typing import Union


def parse(metadata: Dict[str, Any], raw_value: str) -> Union[str, None]:
    """Selset Parser

    Args:
        metadata (Dict[str, Any]): slot metadata
        raw_value (str): value tagged by the model

    Returns:
        Union[str, None]: selset or None if invalid
    """
    normalized = raw_value.lower()
    selections = metadata.get("selections", [])
    for selection in selections:
        name = selection.get("name")
        if name.lower() == normalized:
            return name
        aliases = selection.get("aliases")
        for alias in aliases:
            if alias.lower() == normalized:
                return name
    return None