"""Tests for ScrollModel and ai_mouse.generate_scroll()."""
from __future__ import annotations

import pytest


def test_scroll_model_init_default() -> None:
    from ai_mouse.scroll import ScrollModel
    m = ScrollModel()
    assert m._seq_len > 0
    m.close()


def test_scroll_model_generate_target_mode() -> None:
    from ai_mouse.scroll import ScrollModel
    m = ScrollModel()
    events = m.generate(0, 1500, mode="target")
    assert len(events) >= 5
    total = sum(e["deltaY"] for e in events)
    assert 1000 <= total <= 2000  # broad — quantisation can drift
    assert events[0]["t"] == 0
    assert all(e["deltaMode"] == 0 for e in events)


def test_scroll_model_direction() -> None:
    from ai_mouse.scroll import ScrollModel
    m = ScrollModel()
    events = m.generate(2000, 0, mode="target")
    total = sum(e["deltaY"] for e in events)
    assert total < 0


def test_scroll_invalid_path() -> None:
    from ai_mouse.errors import ModelLoadError
    from ai_mouse.scroll import ScrollModel
    with pytest.raises(ModelLoadError):
        ScrollModel(model_path="/no/such/path")


def test_scroll_model_timestamps_monotonic() -> None:
    from ai_mouse.scroll import ScrollModel
    m = ScrollModel()
    events = m.generate(0, 2000, mode="target")
    times = [e["t"] for e in events]
    for i in range(1, len(times)):
        assert times[i] >= times[i - 1]


def test_scroll_model_deltaY_are_integers() -> None:
    from ai_mouse.scroll import ScrollModel
    m = ScrollModel()
    events = m.generate(0, 2000, mode="target")
    assert all(isinstance(e["deltaY"], int) for e in events)
