"""Ingest meta 规范化 — F9 reality_anchor 默认值。"""

from __future__ import annotations

from typing import Any


def normalize_ingest_meta(meta: dict[str, Any] | None) -> dict[str, Any]:
    """web/user_paste 缺 anchor 时默认 marked_hypothesis，并取消 subject_eligible。"""
    out = dict(meta or {})
    prov = dict(out.get("provenance") or {})
    tier = prov.get("trust_tier")
    if tier not in ("web", "user_paste"):
        return out
    if prov.get("reality_anchor"):
        out["provenance"] = prov
        return out
    prov["reality_anchor"] = "marked_hypothesis"
    out["provenance"] = prov
    if out.get("subject_eligible", True):
        out["subject_eligible"] = False
    return out
