from typing import List


def get_routing_keys(*args, **kwargs) -> List[str]:
    """Get a list of routing keys, ordered from least specific to most specific

    Will return all possible routing keys to get a message to a particular system.

    args is used to specify routing words. The correct order is
       System, Version, Instance, Clone ID

    For instance:

        ['test_system'], is_admin=True:
            ['admin', 'admin.test_system']

        ['test_system', '1.0.0'], is_admin=True:
            ['admin', 'admin.test_system', 'admin.test_system.1-0-0']

        ['test_system', '1.0.0', 'default'], is_admin=True:
            [
                'admin',
                'admin.test_system',
                'admin.test_system.1-0-0',
                'admin.test_system.1-0-0.default',
            ]

        ['test_system', '1.0.0', 'default', 'random_text'], is_admin=True:
            [
                'admin',
                'admin.test_system',
                'admin.test_system.1-0-0',
                'admin.test_system.1-0-0.default',
                'admin.test_system.1-0-0.default.random_text',
            ]

    NOTE: Because RabbitMQ uses '.' as the word delimiter all '.' in routing words will
    be replaced with '-'

    Args:
        List of routing key words to include in the routing keys

    Keyword Args:
        is_admin: Will prepend 'admin' to all generated keys if True

    Returns:
        List of routing keys, ordered from general to specific
    """
    routing_keys = ["admin"] if kwargs.get("is_admin", False) else []

    for arg in (y for y in args if y is not None):
        # Make sure we don't have any extra word delimiters
        new_key = arg.replace(".", "-")

        routing_keys.append(
            routing_keys[-1] + "." + new_key if len(routing_keys) else new_key
        )

    return routing_keys