"""Unit tests for event feature calculations."""


def test_guidance_direction_score_raised():
    from libs.features.event_features import guidance_direction_score
    from libs.schemas.types import GuidanceOutput
    g = GuidanceOutput(status="raised", scope="unknown", notes="")
    assert guidance_direction_score(g) == 1.0


def test_guidance_direction_score_lowered():
    from libs.features.event_features import guidance_direction_score
    from libs.schemas.types import GuidanceOutput
    g = GuidanceOutput(status="lowered", scope="unknown", notes="")
    assert guidance_direction_score(g) == 0.0


def test_guidance_direction_score_maintained():
    from libs.features.event_features import guidance_direction_score
    from libs.schemas.types import GuidanceOutput
    g = GuidanceOutput(status="inline_or_maintained", scope="unknown", notes="")
    assert guidance_direction_score(g) == 0.5


def test_oneoff_penalty_no_flags():
    from libs.features.event_features import oneoff_penalty
    from libs.schemas.types import RiskFlagsOutput
    r = RiskFlagsOutput()
    assert oneoff_penalty(r) == 0.0


def test_oneoff_penalty_all_flags():
    from libs.features.event_features import oneoff_penalty
    from libs.schemas.types import RiskFlagsOutput
    r = RiskFlagsOutput(
        oneoff_item=True,
        tax_benefit=True,
        valuation_gain=True,
        non_gaap_heavy=True,
        financing_related=True,
        legal_or_regulatory_overhang=True,
    )
    assert oneoff_penalty(r) == 1.0


def test_signal_strength_score_all_positive():
    from libs.features.event_features import signal_strength_score
    from libs.schemas.types import SignalsOutput
    s = SignalsOutput(
        demand_strength="strong",
        pricing_power="present",
        backlog_or_bookings="present",
        customer_expansion="present",
        margin_quality="improving",
    )
    assert signal_strength_score(s) == 1.0


def test_signal_strength_score_all_unknown():
    from libs.features.event_features import signal_strength_score
    from libs.schemas.types import SignalsOutput
    s = SignalsOutput(
        demand_strength="unknown",
        pricing_power="unknown",
        backlog_or_bookings="unknown",
        customer_expansion="unknown",
        margin_quality="unknown",
    )
    assert signal_strength_score(s) == 0.0


def test_document_quality_score_range(sample_parser_output):
    from libs.features.event_features import document_quality_score
    from libs.schemas.types import ConfidenceOutput
    c = ConfidenceOutput(**sample_parser_output["confidence"])
    score = document_quality_score(c)
    assert 0.0 <= score <= 1.0


def test_compute_event_features(sample_parser_output):
    from libs.features.event_features import compute_event_features
    features = compute_event_features(sample_parser_output)
    assert "guidance_direction_score" in features
    assert "oneoff_penalty" in features
    assert "signal_strength_score" in features
    assert "document_quality_score" in features
    assert "event_type" in features
    assert "filing_time_bucket" in features
    assert "event_date" in features
