"""Plugin registry for converter discovery."""
from __future__ import annotations

from pathlib import Path
from .converters.base import BaseConverter
from .converters.pdf import PdfConverter
from .types import PipelineConfig


_CONVERTERS: list[type[BaseConverter]] = [PdfConverter]


def register_converter(cls: type[BaseConverter]) -> None:
    """Register a new converter class."""
    _CONVERTERS.append(cls)


def get_converter(path: Path, config: PipelineConfig | None = None) -> BaseConverter:
    """Get appropriate converter for a file path."""
    cfg = config or PipelineConfig()
    for cls in _CONVERTERS:
        converter = cls(cfg)
        if converter.supports(path):
            return converter
    raise ValueError(f"No converter found for: {path.suffix}")
