from typing import List
import pathlib


def get_merged_file_paths(merge: List[str], outfile: str, outdir: str,
                          create_parents: bool = True) -> List[str]:
    """Get the file paths for results of merging translations.

    Args:
        merge: The files to merge into
        outfile: Filename where to write the result
        outdir: Directory where to write the result
        create_parents: If true, create the outdir if it doesn't exist

    Returns:
        The file paths where the results of merging should be saved
    """
    if len(merge) == 1 and outfile:
        return [outfile]
    if len(merge) > 1 and outfile:
        msg = f'Ignoring outfile {outfile} since merging into multiple files'
        print(msg)
    file_paths = []
    default_directory = pathlib.Path('.')
    result_directory = default_directory
    if outdir:
        result_directory = pathlib.Path(outdir)
        if result_directory.is_file():
            msg = f'Cannot use outdir {outdir} as directory. It is a file!'
            raise IOError(msg)
        if create_parents:
            result_directory.mkdir(parents=True, exist_ok=True)
    default_suffix = '-borrow'
    for merge_file in merge:
        this_merge = pathlib.Path(merge_file)
        merge_result = this_merge.stem + default_suffix + this_merge.suffix
        full_merge_result = result_directory / merge_result
        file_paths.append(str(full_merge_result))
    return file_paths