"""
SemanticScholar_get_pdf_snippets

Fetch a paper's open-access PDF from Semantic Scholar and return bounded text snippets around pro...
"""

from typing import Any, Optional, Callable
from ._shared_client import get_shared_client


def SemanticScholar_get_pdf_snippets(
    terms: list[str],
    paper_id: Optional[str] = None,
    open_access_pdf_url: Optional[str] = None,
    window_chars: Optional[int] = 220,
    max_snippets_per_term: Optional[int] = 3,
    max_total_chars: Optional[int] = 8000,
    *,
    stream_callback: Optional[Callable[[str], None]] = None,
    use_cache: bool = False,
    validate: bool = True,
) -> dict[str, Any]:
    """
    Fetch a paper's open-access PDF from Semantic Scholar and return bounded text snippets around pro...

    Parameters
    ----------
    paper_id : str
        Semantic Scholar paper ID (e.g., from SemanticScholar_search_papers). The too...
    open_access_pdf_url : str
        Direct open access PDF URL (recommended when you already have it from Semanti...
    terms : list[str]
        Terms to search for in the extracted full text (case-insensitive).
    window_chars : int
        Context window size (characters) before and after each match.
    max_snippets_per_term : int
        Maximum number of snippets returned per term.
    max_total_chars : int
        Hard cap on total characters returned across all snippets.
    stream_callback : Callable, optional
        Callback for streaming output
    use_cache : bool, default False
        Enable caching
    validate : bool, default True
        Validate parameters

    Returns
    -------
    dict[str, Any]
    """
    # Handle mutable defaults to avoid B006 linting error

    return get_shared_client().run_one_function(
        {
            "name": "SemanticScholar_get_pdf_snippets",
            "arguments": {
                "paper_id": paper_id,
                "open_access_pdf_url": open_access_pdf_url,
                "terms": terms,
                "window_chars": window_chars,
                "max_snippets_per_term": max_snippets_per_term,
                "max_total_chars": max_total_chars,
            },
        },
        stream_callback=stream_callback,
        use_cache=use_cache,
        validate=validate,
    )


__all__ = ["SemanticScholar_get_pdf_snippets"]
