"""Data models for the document subsystem.

DocumentMeta is the DTO carried between DocumentService, Agent tools,
REST routes, and the frontend. It mirrors the ``documents`` DB row.
"""

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime, timezone


def _now_iso() -> str:
    return datetime.now(timezone.utc).isoformat()


@dataclass
class DocumentMeta:
    """Metadata for a generated or uploaded document.

    Attributes:
        id: UUID string (primary key).
        filename: Original/display name (e.g. "report.docx").
        stored_name: On-disk filename (UUID + extension).
        format: One of "word" | "excel" | "pdf".
        size: File size in bytes.
        conversation_id: Conversation this document belongs to.
        created_at: ISO 8601 UTC timestamp.
        download_url: Relative URL for downloading (set by route layer).
    """

    id: str
    filename: str
    stored_name: str
    format: str
    size: int
    conversation_id: str
    created_at: str
    download_url: str = ""

    def to_dict(self) -> dict[str, object]:
        """JSON-safe dict for API responses and tool results."""
        return {
            "id": self.id,
            "filename": self.filename,
            "stored_name": self.stored_name,
            "format": self.format,
            "size": self.size,
            "conversation_id": self.conversation_id,
            "created_at": self.created_at,
            "download_url": self.download_url,
        }
