from g_gremlin.impact import (
    build_impact,
    calculate_time_saved,
    format_time_saved,
    get_gremlin_message,
)


def test_time_saved_calculation():
    stats = {"issues_fixed": 10, "formulas_inspected": 100}
    minutes = calculate_time_saved(stats)
    assert minutes == 10 * 2 + int(100 * 0.1)


def test_format_time_under_hour():
    assert format_time_saved(45) == "~45 minutes"


def test_format_time_over_hour():
    result = format_time_saved(120)
    assert "hour" in result


def test_build_impact_includes_fields():
    impact = build_impact(
        action="Test action",
        stats={"issues_fixed": 5},
        scenario="lint_fixed",
        trophy="🔧",
        fixed=5,
        remaining=0,
    )
    assert "action" in impact and "stats" in impact and "gremlin_says" in impact and "trophy" in impact


def test_gremlin_message_formats():
    msg = get_gremlin_message("lint_found", count=100, issues=5)
    assert any(substr in msg for substr in ["100", "5"])
