from typing import Optional
from enum import Enum


def enum_parse(enum_cls: type, value: str) -> Optional[Enum]:
    """Try to parse a string value to an Enum member."""
    if not issubclass(enum_cls, Enum):
        raise TypeError("Can only be used with classes derived from enum.Enum.")
    if value in enum_cls.__members__:
        return enum_cls.__members__[value]
    val_lc = value.casefold()
    val_map = {name.casefold(): name for name in enum_cls.__members__}
    if val_lc in val_map:
        return enum_cls.__members__[val_map[val_lc]]
    return None