from typing import List
from typing import Dict
import itertools


def reification_master(sort_name: str, sort_args: List[str], domainObj_dict: Dict[str, List[str]]) -> List[str]:
    """
    Function to reify the given sort, i.e. event/fluent, w.r.t the domainObj in the argument
    :param sort_name:  name of the sort
    :param sort_args:  list of arguments to the sort
    :param domainObj_dict: dictionary of all domainObj, with domainObj_names as keys, which maps to instances as a list
    :return: list of reified atoms
    """
    reification_prefix = sort_name                  # "load"

    if len(sort_args) == 0:
        return [reification_prefix]
    else:
        result = []

        domainObj_list = []  # list of lists
        for domainObj in sort_args:
            if domainObj in domainObj_dict.keys():
                domainObj_list.append(domainObj_dict[domainObj])
            else:
                domainObj_list.append([domainObj])

        for permutation in list(itertools.product(*domainObj_list)):
            atom = reification_prefix + "_"         # "load_"

            perm_list = list(permutation)
            for x in perm_list:
                atom += x + "_"                     # "load_a1_a2_"

            atom = atom[:-1]                        # "load_a1_a2"

            result.append(atom)
    
    return result