"""Public API for paper2md."""
from __future__ import annotations

from pathlib import Path
from .types import ConversionResult, PipelineConfig
from .converters.pdf import PdfConverter


def convert(
    path: str | Path,
    config: PipelineConfig | None = None,
) -> ConversionResult:
    """Convert a research paper PDF to Markdown.

    Args:
        path: Path to the PDF file.
        config: Optional pipeline configuration.

    Returns:
        ConversionResult with markdown and extracted metadata.
    """
    path = Path(path)
    if not path.exists():
        raise FileNotFoundError(f"File not found: {path}")

    converter = PdfConverter(config)
    if not converter.supports(path):
        raise ValueError(f"Unsupported file type: {path.suffix}")

    return converter.convert(path)
