from pathlib import Path


def course_with_student_clones(
    course_structure_assignment, tmp_path, test_data
):
    """
    Creates the final piece of a typical course including student cloned
    repos for the assignment. Student names and list of files come
    from test_data fixture.
    """
    config, assignment_name, release_path = course_structure_assignment

    clone_dir = config["clone_dir"]
    students = test_data["students"]
    # Loop through and create a clone repo for each student and add files
    for s in students:
        repo_name = "{}-{}".format(assignment_name, s)
        assignment_path = Path(
            config["course_directory"], clone_dir, assignment_name, repo_name
        )
        assignment_path.mkdir(parents=True, exist_ok=True)
        for f in test_data["files"]:
            fname = Path(f).name
            if f == fname:
                Path(assignment_path, f).touch()
            else:
                fparent = Path(assignment_path, Path(f).parent)
                fparent.mkdir(parents=True, exist_ok=True)
                Path(fparent, fname).touch()
    return config, assignment_name, students