import itertools
from typing import Tuple
from typing import List
from typing import Dict
from typing import Any


def expand_config_template_variables(key_min_max_tuples: Tuple[Tuple[str, ...], ...],
                                     key_value_tuples: Tuple[Tuple[str, ...], ...]) -> List[Dict[str, Any]]:
    """
    Helper that computes a list of key-value dictionaries
    from all value-combinations of key-min-max and key-value
    assignments.
    """
    keys = [k for k, _, _ in key_min_max_tuples] + [k for k, _ in key_value_tuples]
    # noinspection PyTypeChecker
    values_iterators = [(range(int(min_value), int(max_value) + 1))
                        for _, min_value, max_value in key_min_max_tuples] \
                       + [(value,) for _, value in key_value_tuples]
    if not values_iterators:
        return []
    return [{k: v for k, v in zip(keys, values)}
            for values in itertools.product(*values_iterators)]