from hockey_data.service import HockeyDataService


def penalty(side):
    return {
        "side": side,
        "infraction": {"id": "minor"},
        "preset": "2m",
        "durationMs": 120000,
        "remainingMs": 120000,
        "finished": False,
    }


def payload(home, away, labels=None):
    settings = {
        "strength_regulation_skaters": 5,
        "strength_regular_overtime_skaters": 3,
        "strength_playoff_overtime_skaters": 5,
        "strength_min_skaters": 3,
        "strength_state_labels": labels or {
            "regulation": {
                "5x4": {"ru": "Играют в большинстве"},
                "5x3": {"ru": "5 на 3"},
                "4x4": {"ru": "4 на 4"},
                "4x3": {"ru": "4 на 3"},
            }
        },
    }
    timer_state = {"penalty_board": {"penalties": [penalty("home") for _ in range(home)] + [penalty("away") for _ in range(away)]}}
    return HockeyDataService._strength_payload(settings, stage="regular", current_period="1", timer_state=timer_state, language="ru")


def test_one_home_penalty_uses_5_on_4_on_penalized_side():
    result = payload(1, 0)
    assert result["home_label"] == "Играют в большинстве"
    assert result["away_label"] == "Играют в большинстве"


def test_two_home_penalties_use_5_on_3_condition():
    result = payload(2, 0)
    assert result["home_label"] == "5 на 3"
    assert result["away_label"] == "5 на 3"


def test_equal_mutual_penalties_use_equal_numeric_condition_on_both_sides():
    result = payload(1, 1)
    assert result["home_label"] == "4 на 4"
    assert result["away_label"] == "4 на 4"


def test_complex_two_vs_one_keeps_majority_caption_and_numeric_penalty_side():
    labels = {"regulation": {"4x3": {"ru": "Большинство 4 на 3"}}}
    result = payload(2, 1, labels)
    assert result["advantage_side"] == "away"
    assert result["home_label"] == "Большинство 4 на 3"
    assert result["away_label"] == "Большинство 4 на 3"
