"""ai_mouse — ONNX Runtime SDK for human-like mouse trajectories and scroll events.

Public API:

    from ai_mouse import generate, generate_scroll, MouseModel, ScrollModel

See the project README for usage examples.
"""
from __future__ import annotations

from collections.abc import Sequence
from pathlib import Path
from typing import Literal

from ai_mouse import errors
from ai_mouse._model_cache import get_mouse_model, get_scroll_model
from ai_mouse.mouse import MouseModel
from ai_mouse.scroll import ScrollModel

__version__ = "0.2.0"

__all__ = [
    "MouseModel",
    "ScrollModel",
    "errors",
    "generate",
    "generate_scroll",
    "__version__",
]


def generate(
    start: tuple[int, int],
    end: tuple[int, int],
    *,
    n_points: int = 64,
    speed: float | None = None,
    click: bool = True,
    seed: int | None = None,
    model_path: str | Path | None = None,
    providers: Sequence[str] | None = None,
) -> list[tuple[int, int, int]]:
    """Generate a human-like mouse trajectory.

    See :meth:`MouseModel.generate` for argument semantics.
    The underlying :class:`MouseModel` is cached process-wide; repeat
    calls with the same ``(model_path, providers)`` reuse the session.
    """
    model = get_mouse_model(model_path, providers)
    return model.generate(
        start=start,
        end=end,
        n_points=n_points,
        speed=speed,
        click=click,
        seed=seed,
    )


def generate_scroll(
    start_scroll_y: int,
    target_scroll_y: int,
    *,
    mode: Literal["target", "fast", "precise"] = "target",
    viewport_height: int = 800,
    seed: int | None = None,
    model_path: str | Path | None = None,
    providers: Sequence[str] | None = None,
) -> list[dict]:
    """Generate a sequence of mouse-wheel events. See :class:`ScrollModel.generate`."""
    model = get_scroll_model(model_path, providers)
    return model.generate(
        start_scroll_y=start_scroll_y,
        target_scroll_y=target_scroll_y,
        mode=mode,
        viewport_height=viewport_height,
        seed=seed,
    )
