import os


def analyze_legibility(file_path: str) -> tuple[float, list[str], str]:
    """
    MVP de OCR/legibilidade:
    - verifica se o ficheiro existe
    - tenta ler texto simples
    - score baseado em tamanho do texto
    """

    problemas = []

    if not os.path.exists(file_path):
        return 0.0, ["Ficheiro não encontrado"], ""

    try:
        with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
            text = f.read()
    except Exception:
        return 0.2, ["Não foi possível ler o documento"], ""

    text_len = len(text.strip())

    if text_len == 0:
        return 0.1, ["Documento sem texto legível"], ""

    if text_len < 200:
        problemas.append("Texto muito curto, possível baixa legibilidade")
        return 0.5, problemas, text

    return 0.9, problemas, text
