# fitz_ai/retrieval/engine.py
from __future__ import annotations

from dataclasses import dataclass
from typing import Any, List

from fitz_ai.engines.classic_rag.models.chunk import Chunk
from fitz_ai.engines.classic_rag.retrieval.base import RetrievalPlugin
from fitz_ai.engines.classic_rag.retrieval.registry import get_retrieval_plugin


@dataclass(slots=True)
class RetrieverEngine:
    """
    Thin orchestration layer around a retrieval plugin.

    Responsibilities:
    - Choose a retrieval plugin by name (via registry)
    - Construct plugin instance with caller-provided dependencies
    - Delegate `retrieve` calls
    """

    plugin: RetrievalPlugin

    @classmethod
    def from_name(cls, name: str, **plugin_kwargs: Any) -> "RetrieverEngine":
        plugin_cls = get_retrieval_plugin(name)
        plugin = plugin_cls(**plugin_kwargs)  # type: ignore[arg-type]
        return cls(plugin=plugin)

    def retrieve(self, query: str) -> List[Chunk]:
        return self.plugin.retrieve(query)
