# edited by glg
from pypos.modules.scanner.services.scanner_event_guard_service import (
    ScannerEventGuardService,
)


def test_scanner_burst_40_unique_items_accepted():
    svc = ScannerEventGuardService(dedup_window_ms=180)
    base = 8990000000000
    accepted = 0
    for idx in range(40):
        barcode = str(base + idx)
        if svc.should_accept(barcode, "rawinput_poll"):
            accepted += 1
    assert accepted == 40


def test_scanner_burst_cross_source_duplicate_rejected():
    svc = ScannerEventGuardService(dedup_window_ms=1000)
    for idx in range(40):
        barcode = f"8991{idx:08d}"
        assert svc.should_accept(barcode, "rawinput_poll") is True
        # Duplikat barcode yang sama dari source lain dalam jendela dedup harus ditolak.
        assert svc.should_accept(barcode, "manual_barcode") is False
