import copy


def haskey(element, keys, default=None, return_remaining=False):
    """
    Check if keys (nested) exists in `element` (dict).
    """
    if element is None or keys is None:
        return default

    if not isinstance(element, dict):
        raise TypeError(f"haskey() expects dict as element, got {type(element)}")

    if not isinstance(keys, list):
        raise TypeError(
            f"haskey() expects list of object type str as keys, got {type(keys)}"
        )

    _element = element
    _keys = copy.deepcopy(keys)
    for key in _keys[:]:
        try:
            _element = _element[key]
            _keys.remove(key)
        except (KeyError, TypeError):
            if return_remaining:
                return default, (_element, _keys)
            return default

    if return_remaining:
        return _element, (_element, _keys)
    return _element