from __future__ import annotations

import copy

def normalize_omnimarket_v0_contract(raw: dict[str, object]) -> dict[str, object]:
    """Rewrite an omnimarket v0 contract dict to the canonical shape.

    Compatibility-stripping transform, not a semantic migration. The
    ``handler``, ``descriptor``, and ``terminal_event`` blocks are dropped
    entirely; ``descriptor.node_archetype``, ``descriptor.timeout_ms``,
    and the ``terminal_event`` topic string are not carried forward.
    Callers that need this information must extract it before running
    the normalizer.

    The only field salvaged is ``handler.input_model``, which is hoisted
    to a root-level ``input_model`` when not already present.
    """
    result = copy.deepcopy(raw)
    handler_block = result.pop("handler", None)
    result.pop("descriptor", None)
    result.pop("terminal_event", None)
    if (
        isinstance(handler_block, dict)
        and "input_model" in handler_block
        and "input_model" not in result
    ):
        result["input_model"] = handler_block["input_model"]
    return result
