from pathlib import Path


def tmpdir_for_subworkflow(tmpdir_factory, wdl_main, wdl_sub, wdl_subsub, wdl_sub2):
    """Temporary directory with main WDL and all imported sub WDLs
    in a correct directory structure.

    There are 3 files on this directory.
        - main WDL: main.wdl
        - sub WDL: sub/sub.wdl
        - sub2 WDL: sub2/sub2.wdl

    Returns a PathLib object of the root directory.
    """
    root = tmpdir_factory.mktemp('main')
    root.mkdir('sub')
    root.mkdir('sub2')

    Path(root / 'main.wdl').write_text(wdl_main)
    Path(root / 'sub' / 'sub.wdl').write_text(wdl_sub)
    Path(root / 'sub' / 'subsub.wdl').write_text(wdl_subsub)
    Path(root / 'sub2' / 'sub2.wdl').write_text(wdl_sub2)

    return root