from typing import Dict
from typing import Any


def convert_dict_to_yaml(input_dict: Dict[str, Any], indent_spaces: int = 4, indent_level: int = 0) -> str:
    """
    The original yaml.dump needed improvements, this is a recursive re-implementation

    yaml.dump(config_dict)

    Args:
        input_dict: Dict to be converted to yaml.
        indent_spaces: How many spaces per indent level.
        indent_level: Current indent level for the recursion.

    Returns:
        YAML string.
    """
    # setup key-value collector and indent level
    ret_list = []
    indent = " " * (indent_level * indent_spaces)
    # loop input dict
    for key, value in input_dict.items():
        # setup collector for single key-value pair
        single_ret_list = [f"{indent}{key}:"]
        # check type
        if isinstance(value, bool):
            # bools as lower-case
            value_str = str(value).lower()
        elif isinstance(value, (int, float)):
            # leave float conversion to python
            value_str = str(value)
        elif isinstance(value, str):
            # put quotes around strings
            value_str = f"\"{value}\""
        elif value is None:
            # None is null in yaml
            value_str = "null"
        elif isinstance(value, dict):
            # iterate dictionaries recursively
            value_str = "\n" + convert_dict_to_yaml(value, indent_spaces=indent_spaces, indent_level=indent_level + 1)
        else:
            raise ValueError(f"dict to yaml, value type not understood: {value}")
        # concatenate the single key-value pair and add it to the key-value collector
        single_ret_list += [f" {value_str}"]
        ret_list += ["".join(single_ret_list)]
    # join the collected key-value pairs with newline
    return "\n".join(ret_list)