from __future__ import annotations

from dataclasses import dataclass, field
from typing import Any, Mapping, Sequence
from uuid import UUID


@dataclass(frozen=True)
class DocumentIngestRequest:
    """
    Immutable description of a document ingest request.
    """

    source_url: str
    collection_name: str
    mime_type: str = "application/pdf"
    embedding_backend: str | None = None
    metadata: Mapping[str, Any] | None = None
    chunk_size_tokens: int = 800
    chunk_overlap_tokens: int = 200


@dataclass(frozen=True)
class DocumentIngestContext:
    """
    Context shared across strategies (conversation metadata, etc.).
    """

    conversation_id: UUID
    default_metadata: Mapping[str, Any] = field(default_factory=dict)


@dataclass(frozen=True)
class DownloadedDocument:
    """
    Result of downloading a document from a remote source.
    """

    content: bytes
    url: str
    mime_type: str
    filename: str | None = None


@dataclass(frozen=True)
class Chunk:
    """
    Represents a single chunk about to be embedded and stored.
    """

    chunk_id: str
    text: str
    token_count: int
    byte_count: int
    metadata: Mapping[str, Any]


@dataclass(frozen=True)
class DocumentIngestResult:
    """
    Summary emitted by the pipeline once persistence finishes.
    """

    inserted_chunks: int
    collection_name: str
    chunk_ids: Sequence[str]
    embedding_backend: str
    metadata: Mapping[str, Any] = field(default_factory=dict)
