import asyncio

from pipeline.enricher import enrich_events


def test_enrich_basic():
    db = {"web": {"region": "us-east", "tier": "pro"}}
    events = [
        {"source": "web", "event_id": "e1", "value": 42},
        {"source": "api", "event_id": "e2", "value": 10},
    ]
    result = asyncio.run(enrich_events(events, db))
    assert len(result) == 2
    assert result[0]["region"] == "us-east"
    assert "fingerprint" in result[0]


def test_enrich_large_batch():
    """Production-scale enrichment — this async endpoint is too slow."""
    sources = [f"source-{i}" for i in range(20)]
    db = {
        s: {"region": f"region-{i % 5}", "tier": "pro"}
        for i, s in enumerate(sources)
    }
    events = []
    for i in range(30_000):
        events.append(
            {
                "source": sources[i % len(sources)],
                "event_id": f"evt-{i:08d}",
                "category": f"cat-{i % 100}",
                "value": float(i % 1000),
                "payload": f"data-field-{i}-with-extra-content-for-normalization",
                "timestamp": f"2024-01-{(i % 28) + 1:02d}T{i % 24:02d}:00:00Z",
            }
        )
    result = asyncio.run(enrich_events(events, db))
    assert len(result) == 30_000
    assert all("fingerprint" in r for r in result)
