"""Nova Decommission Transform — zero counts + disable deletion protection (REQ-92).

Extracted from core/contract_resolver.py (P12, REQ-176).

G-113 import direction: this module imports only stdlib. The re-export
shim core/contract_resolver.py imports this module. Nothing imports the
shim except external callers.
"""

from __future__ import annotations


def decommission_transform(stack_instance):
    """REQ-92: Transform a resolved stack instance for decommission.

    Sets all scalable counts to 0 and deletion_protection to false on
    every resource. Used by the decommission pipeline mode after the
    first step (disable deletion protection) has been applied.
    """
    for res in stack_instance.get("resources", []):
        if "nfrs" not in res:
            res["nfrs"] = {}
        res["nfrs"]["deletion_protection"] = False
        inputs = res.get("inputs", {})
        if "desired_count" in inputs:
            inputs["desired_count"] = 0
        if "min_capacity" in inputs:
            inputs["min_capacity"] = 0
        if "max_capacity" in inputs:
            inputs["max_capacity"] = 0
    return stack_instance