"""
iPTMnet_search

Search the iPTMnet database for proteins with post-translational modification (PTM) data. Find pr...
"""

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


def iPTMnet_search(
    operation: str,
    search_term: str,
    role: Optional[str] = "Substrate",
    ptm_type: Optional[str | Any] = None,
    term_type: Optional[str] = "All",
    max_results: Optional[int] = 25,
    *,
    stream_callback: Optional[Callable[[str], None]] = None,
    use_cache: bool = False,
    validate: bool = True,
) -> list[Any]:
    """
    Search the iPTMnet database for proteins with post-translational modification (PTM) data. Find pr...

    Parameters
    ----------
    operation : str
        Operation type
    search_term : str
        Search query: gene name (TP53, EGFR, AKT1), protein name (p53, insulin recept...
    role : str
        Filter by protein role. Substrate = proteins that are modified; Enzyme = prot...
    ptm_type : str | Any
        Filter by PTM type: Phosphorylation, Acetylation, Ubiquitination, Methylation...
    term_type : str
        Type of search term. Default: All (searches across all fields)
    max_results : int
        Maximum results to return (default: 25)
    stream_callback : Callable, optional
        Callback for streaming output
    use_cache : bool, default False
        Enable caching
    validate : bool, default True
        Validate parameters

    Returns
    -------
    list[Any]
    """
    # Handle mutable defaults to avoid B006 linting error

    # Strip None values so optional parameters don't trigger schema validation errors
    _args = {
        k: v
        for k, v in {
            "operation": operation,
            "search_term": search_term,
            "role": role,
            "ptm_type": ptm_type,
            "term_type": term_type,
            "max_results": max_results,
        }.items()
        if v is not None
    }
    return get_shared_client().run_one_function(
        {
            "name": "iPTMnet_search",
            "arguments": _args,
        },
        stream_callback=stream_callback,
        use_cache=use_cache,
        validate=validate,
    )


__all__ = ["iPTMnet_search"]
