from __future__ import annotations

from pathlib import Path
from typing import Iterable, Iterator


def is_allowed(path: Path, allowed_extensions: Iterable[str]) -> bool:
    return path.suffix.lower() in {ext.lower() for ext in allowed_extensions}


def read_text_file(path: Path) -> str:
    return path.read_text(encoding="utf-8", errors="ignore")


def iter_text_files(
    paths: Iterable[Path], allowed_extensions: Iterable[str]
) -> Iterator[tuple[Path, str]]:
    for path in paths:
        if not path.is_file():
            continue
        if not is_allowed(path, allowed_extensions):
            continue
        yield path, read_text_file(path)
