from __future__ import annotations

from typing import Mapping, Protocol, Sequence

from .models import (
    Chunk,
    DocumentIngestContext,
    DocumentIngestRequest,
    DownloadedDocument,
)


class DocumentDownloader(Protocol):
    async def fetch(self, request: DocumentIngestRequest) -> DownloadedDocument: ...


class TextExtractor(Protocol):
    async def extract(self, document: DownloadedDocument) -> str: ...


class DocumentNormalizer(Protocol):
    def normalize(self, text: str) -> str: ...


class ChunkingStrategy(Protocol):
    def chunk(
        self,
        text: str,
        request: DocumentIngestRequest,
        context: DocumentIngestContext,
    ) -> Sequence[Chunk]: ...


class EmbeddingStrategy(Protocol):
    name: str

    async def embed(self, texts: Sequence[str]) -> Sequence[Sequence[float]]: ...


class MetadataBuilder(Protocol):
    def build(
        self,
        chunk: Chunk,
        request: DocumentIngestRequest,
        context: DocumentIngestContext,
    ) -> Mapping[str, object]: ...


class VectorStoreWriter(Protocol):
    async def write(
        self,
        collection_name: str,
        chunks: Sequence[Chunk],
        embeddings: Sequence[Sequence[float]],
    ) -> Sequence[str]: ...
