from typing import Union
from typing import Dict
from typing import List


def to_tags(values: Union[Dict, List, str], sep: str = ",") -> List[str]:
    """ Coerce the passed values into a list of colon separated key-value pairs.

        dict example:
            {"tag1": "value1", "tag2": "value2", ...}
                 -> ["tag1:value1", "tag2:value2", ...]

        list example:
            ["tag1", "tag2", ...] -> ["tag1", "tag2", ...]

        str example (comma-delimited):
            "tag1:value1, tag2:value2", ..." -> ["tag1:value1", "tag2:value2", ...]

        str example (single):
            "tag1:value1" -> ["tag1:value1"]
    """
    result: List[str] = []
    if isinstance(values, dict):
        result = [
            f"{key}:{str(value).lower().replace(' ','_')}"
            for key, value in values.items()
            if isinstance(value, (str, int))
        ]
    elif isinstance(values, str):
        if "," in values:
            result = values.split(sep)
        else:
            result = [values]
    elif isinstance(values, list):
        result = values
    else:
        result = []

    return result