from fxhnt.application.paper_book import DrawdownKillSwitch


def test_not_killed_before_threshold():
    ks = DrawdownKillSwitch(kill_dd=0.15, reenter_dd=0.07)
    ks.observe(-0.10)            # 10% dd < 15%
    assert ks.killed is False


def test_kills_past_threshold():
    ks = DrawdownKillSwitch(kill_dd=0.15, reenter_dd=0.07)
    ks.observe(-0.20)            # 20% dd > 15%
    assert ks.killed is True


def test_reenters_after_recovery_with_hysteresis():
    ks = DrawdownKillSwitch(kill_dd=0.15, reenter_dd=0.07)
    ks.observe(-0.20); assert ks.killed is True       # killed
    ks.observe(0.05);  assert ks.killed is True        # dd still ~16% > 7% -> stay killed (hysteresis)
    ks.observe(0.12);  assert ks.killed is False       # recovered inside 7% -> re-enter


def test_decision_uses_prior_state_only():
    ks = DrawdownKillSwitch(kill_dd=0.15, reenter_dd=0.07)
    assert ks.killed is False    # initial: not killed
    ks.observe(-0.20)
    assert ks.killed is True
