# edited by glg

from pypos.modules.penjualan.services.high_qty_authorization_service import (
    HighQtyAuthorizationService,
)


def test_high_qty_authorization_once_per_product():
    svc = HighQtyAuthorizationService(max_qty=99)
    assert svc.needs_authorization("A", 120) is True
    svc.mark_authorized("A")
    assert svc.needs_authorization("A", 120) is False


def test_high_qty_authorization_different_product_still_requires_verification():
    svc = HighQtyAuthorizationService(max_qty=99)
    svc.mark_authorized("A")
    assert svc.needs_authorization("B", 150) is True


def test_high_qty_authorization_reset_and_clear_product():
    svc = HighQtyAuthorizationService(max_qty=99)
    svc.mark_authorized("A")
    assert svc.needs_authorization("A", 120) is False

    svc.clear_produk("A")
    assert svc.needs_authorization("A", 120) is True

    svc.mark_authorized("A")
    assert svc.needs_authorization("A", 120) is False
    svc.reset()
    assert svc.needs_authorization("A", 120) is True


def test_high_qty_authorization_respects_threshold_from_config_value():
    svc = HighQtyAuthorizationService(max_qty=200)
    assert svc.needs_authorization("A", 200) is False
    assert svc.needs_authorization("A", 201) is True
