"""JSONB-compatible normalization for newly persisted immutable match reports.

PostgreSQL JSONB represents numbers as ``numeric`` and discards the sign of
IEEE-754 negative zero. Hashing a raw engine report before JSONB storage could
therefore seal ``-0.0`` while the database holds ``0.0``, invalidating a
legitimate report. Prepare a *copy* for persistence; leave engine outcomes and
versioned engine serialization untouched.

This is intentionally a write-boundary helper, not a permissive hash verifier.
Immutable historical evidence is never modified or silently accepted.
"""
from __future__ import annotations

from typing import Any


def normalize_report_payload_for_jsonb(value: Any) -> Any:
    """Return JSON-compatible payload with signed floating zero normalized.

    Also copies every container so mutation of persistence payload can never
    mutate the engine's original authoritative report.
    """
    if isinstance(value, dict):
        return {key: normalize_report_payload_for_jsonb(item) for key, item in value.items()}
    if isinstance(value, (list, tuple)):
        return [normalize_report_payload_for_jsonb(item) for item in value]
    if isinstance(value, float) and value == 0.0:
        return 0.0
    return value
