from docx import Document


def extract_text_from_docx(file_path: str) -> str:
    """
    Extrai texto completo de um ficheiro DOCX, incluindo tabelas.
    """

    document = Document(file_path)
    full_text = []

    # Extrair parágrafos
    for paragraph in document.paragraphs:
        if paragraph.text.strip():
            full_text.append(paragraph.text)

    # Extrair texto de tabelas
    for table in document.tables:
        for row in table.rows:
            row_text = []
            for cell in row.cells:
                cell_text = cell.text.strip()
                if cell_text:
                    row_text.append(cell_text)

            if row_text:
                full_text.append(" | ".join(row_text))

    return "\n".join(full_text)
