from __future__ import annotations

from pathlib import Path

from scripts.twitter_archive.compute_hashtag_metrics import build_hashtag_metrics


def test_build_hashtag_metrics_counts_posts_media_overlap_and_cooccurrence() -> None:
    tweets = [
        {
            "tweet_id": "1",
            "created_at": "Sat Mar 01 12:00:00 +0000 2025",
            "hashtags": ["timmyTime"],
        },
        {
            "tweet_id": "2",
            "created_at": "Sat Mar 15 12:00:00 +0000 2025",
            "hashtags": ["TimmyChain", "timmyTime", "Bitcoin"],
        },
        {
            "tweet_id": "3",
            "created_at": "Sat Apr 05 12:00:00 +0000 2025",
            "hashtags": ["TimmyChain"],
        },
    ]
    media_records = [
        {"tweet_id": "1", "hashtags": ["timmyTime"], "media_type": "video", "created_at": "Sat Mar 01 12:00:00 +0000 2025"},
        {"tweet_id": "2", "hashtags": ["TimmyChain", "timmyTime", "Bitcoin"], "media_type": "animated_gif", "created_at": "Sat Mar 15 12:00:00 +0000 2025"},
    ]

    metrics = build_hashtag_metrics(tweets, media_records, ["timmyTime", "TimmyChain"])

    assert metrics["targets"]["timmytime"]["total_posts"] == 2
    assert metrics["targets"]["timmychain"]["total_posts"] == 2
    assert metrics["targets"]["timmytime"]["media_posts"] == 2
    assert metrics["targets"]["timmychain"]["media_posts"] == 1
    assert metrics["overlap"]["tweet_posts"] == 1
    assert metrics["overlap"]["media_posts"] == 1
    assert metrics["targets"]["timmytime"]["monthly_post_counts"]["2025-03"] == 2
    assert metrics["targets"]["timmychain"]["monthly_post_counts"]["2025-04"] == 1
    assert metrics["targets"]["timmychain"]["top_cooccurring_hashtags"][0]["tag"] == "bitcoin"


def test_project_doc_mentions_hashtag_metrics_outputs() -> None:
    project = Path("twitter-archive/PROJECT.md").read_text()

    assert "hashtag_metrics.json" in project
    assert "hashtag_metrics.md" in project
    assert "#timmyTime" in project
    assert "#TimmyChain" in project
