from typing import Union
from typing import List
from pathlib import Path


def check_path_suffix(path_str: str,
                      allowed_suffix: Union[str, List[str]] = '') -> bool:
    """Check whether the suffix of the path is allowed.

    Args:
        path_str (str):
            Path to check.
        allowed_suffix (List[str], optional):
            What extension names are allowed.
            Offer a list like ['.jpg', ',jpeg'].
            When it's [], all will be received.
            Use [''] then directory is allowed.
            Defaults to [].

    Returns:
        bool:
            True: suffix test passed
            False: suffix test failed
    """
    if isinstance(allowed_suffix, str):
        allowed_suffix = [allowed_suffix]
    pathinfo = Path(path_str)
    suffix = pathinfo.suffix.lower()
    if len(allowed_suffix) == 0:
        return True
    if pathinfo.is_dir():
        if '' in allowed_suffix:
            return True
        else:
            return False
    else:
        for index, tmp_suffix in enumerate(allowed_suffix):
            if not tmp_suffix.startswith('.'):
                tmp_suffix = '.' + tmp_suffix
            allowed_suffix[index] = tmp_suffix.lower()
        if suffix in allowed_suffix:
            return True
        else:
            return False