from typing import List
import difflib


def _get_case_insensitive_close_matches(
    word: str, possibilities: List[str], n: int = 3, cutoff: float = 0.6
) -> List[str]:
    """A case-insensitive wrapper around difflib.get_close_matches.

    Args:
        word : A string for which close matches are desired.
        possibilites : A list of strings against which to match word.
        n : the maximum number of close matches to return. n must be > 0.
        cutoff : Possibilities that don't score at least that similar to word are ignored.

    Returns:
        The best (no more than n) matches among the possibilities are returned in a list,
        sorted by similarity score, most similar first.

    Examples:
        >>> from ee_extra.utils import _get_case_insensitive_close_matches
        >>> _get_case_insensitive_close_matches("mse", ["MSE", "ERGAS"])
        ["MSE"]
    """
    lower_matches = difflib.get_close_matches(
        word.lower(), [p.lower() for p in possibilities], n, cutoff
    )
    return [p for p in possibilities if p.lower() in lower_matches]