import re
import fnmatch


def build_pattern(pattern_algorithm: str, pattern: str, case_insensitive: bool) -> re.Pattern[str]:
    """
    Build a matching object from the pattern given.

    :param pattern_algorithm: A pattern matching algorithm.
    :param pattern: A pattern text.
    :param case_insensitive: True if the matching is performed in case-insensitive, False otherwise.
    :return A matching object built.
    """
    if pattern_algorithm == 'basic':
        pattern = re.escape(pattern)
    elif pattern_algorithm == 'wildcard':
        pattern = fnmatch.translate(pattern)
    elif pattern_algorithm == 'regex':
        pass
    else:
        raise ValueError(f'Invalid pattern algorithm: {pattern_algorithm}')

    return re.compile(pattern, re.IGNORECASE if case_insensitive else 0)