from __future__ import annotations

from dataclasses import dataclass, field
from typing import Protocol


@dataclass
class SourceDocument:
    """Generic document from any standards body."""

    name: str  # Unique identifier (e.g. "draft-foo-bar", "webnn-api")
    title: str
    abstract: str
    source: str  # "ietf", "w3c", etc.
    source_id: str = ""  # Body-specific ID
    source_url: str = ""  # Canonical URL
    full_text: str | None = None
    time: str = ""  # ISO date
    doc_status: str = ""  # "active", "published", "expired", etc.
    extra: dict = field(default_factory=dict)  # Body-specific metadata


class SourceFetcher(Protocol):
    """Protocol for standards body fetchers."""

    def search(
        self, keywords: list[str], since: str | None = None
    ) -> list[SourceDocument]: ...

    def download_text(self, doc: SourceDocument) -> str | None: ...

    def close(self) -> None: ...
