from __future__ import annotations

from apps.books.models import EBook


def subjects_from_ebook(ebook: EBook) -> list[str]:
    ol = (ebook.metadata_json or {}).get("openlibrary") or {}
    return [s.strip() for s in (ol.get("subjects") or []) if isinstance(s, str) and s.strip()]
