import copy


def merge_dict(original_data, new_data):
    """
    Merge two dictionaries.
   
    Merge the content of a `new` dictionary into another, `original` dictionary.
    A new dictionary with the merged content is created. Values are preserved
    and a ValueError is raised if incompatible content is encountered.
    Overlapping lists are extended and nested dictionaries are merged
    recursively.

    Parameters
    ----------
    original_data : dict
        data to merge in the already existing json file
    new_data : dict
        the already existing json file convert to dict

    Raises
    ----------
    ValueError
        if the data type of the value is neither iterable or basic dtype

    """
    # deep copying input dictionary to not overwrite existing values in-place
    result = copy.deepcopy(original_data)
    for key in new_data.keys():
        if key not in original_data:
            # new entry that does not exist -> just added it
            result[key] = new_data[key]
        else:
            # deal with simple data types
            if not isinstance(original_data[key], (list, dict)):
                if new_data[key] == original_data[key]:
                    continue
                else:
                    # contradicting values can not be merged
                    raise ValueError(f"Error different values for the same key "
                                     f"{key}: {new_data[key]} "
                                     f"{original_data[key]}")

            # merge lists by concatenation of values
            if type(original_data[key]) == list:
                result[key].extend(new_data[key])
            # merge dictionaries recursively
            elif type(original_data[key]) == dict:
                result[key] = merge_dict(result[key], new_data[key])
            else:
                raise ValueError(f"Can not merge unexpected data type: "
                                 f"{type(original_data[key])}")

    return result