from __future__ import annotations

from datetime import datetime
from zoneinfo import ZoneInfo

from app.services.request_traffic_service import _format_period, _period_sequence


def test_peak_traffic_period_labels_cover_all_grains() -> None:
    assert _format_period("minute", "202608111405") == "2026-08-11 14:05"
    assert _format_period("hour", "2026081114") == "2026-08-11 14:00"
    assert _format_period("day", "20260811") == "2026-08-11"
    assert _format_period("week", "2026-W33") == "2026 年第 33 周"


def test_period_sequence_includes_empty_time_buckets() -> None:
    timezone = ZoneInfo("Asia/Shanghai")
    start = datetime(2026, 8, 11, 14, 58, tzinfo=timezone)
    end = datetime(2026, 8, 11, 15, 1, tzinfo=timezone)
    assert _period_sequence("minute", start, end) == ["202608111458", "202608111459", "202608111500", "202608111501"]
    assert _period_sequence("hour", start, end) == ["2026081114", "2026081115"]
