from __future__ import annotations

from typing import Iterable

from core.models import Message


def normalize_message_text(message: Message) -> str:
    text = str(getattr(message, "text", "") or "").strip()
    return text or "(no text)"


def plain_text_lines(messages: Iterable[Message]) -> list[str]:
    return [normalize_message_text(message) for message in list(messages)]


def plain_text_blob(messages: Iterable[Message]) -> str:
    return "\n".join(plain_text_lines(messages))
