import json
from pathlib import Path

LANGS = ["en", "es", "fr", "ja"]
MANIFEST = Path("simulator/sample_media/manifest.json")


def _tier_len(v):
    return len(v) if isinstance(v, list) else 0  # 0 = plain string


def test_every_clip_has_all_languages_with_matching_shape():
    manifest = json.loads(MANIFEST.read_text(encoding="utf-8"))
    for clip in manifest["clips"]:
        s = clip.get("strings", {})
        en = s.get("en")
        if not en:
            continue
        for lang in LANGS:
            assert lang in s, f"{clip['id']} missing language {lang}"
            assert set(s[lang]) == set(en), f"{clip['id']}/{lang} key-set differs from en"
            for key, en_val in en.items():
                assert _tier_len(s[lang][key]) == _tier_len(en_val), (
                    f"{clip['id']}/{lang}/{key} tier-count differs from en"
                )
