from typing import List
from typing import Dict
from typing import Any


def split_docker_list(d_list: List[Dict[str, Any]]):
    """Splits the list of docker in test generation docker and test environment docker.

    The split is done by checking for the 'generator' key in the dockers dict defined in the json file.
    Only the docker for the test case / test data generation should contain that key. All others, which are used to set
     the environment for running the tests, must not have it.

    Args:
        d_list: list of dictionaries with docker information

    Returns:
        (list, list):
            - list of dictionaries with test generator docker information (can not contain more than one element)
            - list of dictionaries with test environment docker information

    Raises:
        RuntimeError: if there is more than one test generator docker defined.
    """
    test_d_list = []
    generator_d_list = []
    num_test_generator = 0
    for docker in d_list:
        if "generator" in [*docker]:
            generator_d_list.append(docker)
            num_test_generator += 1
            if num_test_generator > 1:
                error_msg = "More than one docker is defined as 'generator'. " \
                            "Only one item in dockerlist json file should contain the 'generator' key."
                raise RuntimeError(error_msg)
        else:
            test_d_list.append(docker)
    return generator_d_list, test_d_list