from typing import Union
from typing import List
from typing import Dict
from typing import Any
import json


def _build_nlp_response_lookup(
    mapping_file_path: Union[str, List[str]]
) -> Dict[str, Any]:
    """Builds an NLP response lookup dictionary of text -> response json"""
    lookup_dict: Dict[str, Any] = {}
    paths = (
        [mapping_file_path] if isinstance(mapping_file_path, str) else mapping_file_path
    )
    for path in paths:
        with open(path, "r", encoding="utf-8") as path_file:
            path_response_map = json.load(path_file)
        for text, response in path_response_map.items():
            if text not in lookup_dict:
                lookup_dict[text] = response

    return lookup_dict