from typing import Callable
from typing import Dict
import uuid


def _guid_replacer() -> Callable[[str], str]:
    """
    Closure for replace_guid.

    Returns
    -------
    Callable[[str], str]
        replace_guid function

    """
    guid_map: Dict[str, str] = {}

    def _replace_guid(guid: str) -> str:
        """
        Replace GUID/UUID with mapped random UUID.

        Parameters
        ----------
        guid : str
            Input UUID.

        Returns
        -------
        str
            Mapped UUID

        """
        if not guid or not isinstance(guid, str):
            return guid

        if guid in guid_map:
            return guid_map[guid]
        new_guid = str(uuid.uuid4())
        guid_map[guid] = new_guid
        return new_guid

    return _replace_guid