from __future__ import annotations


def execute(payload: dict) -> dict:
    current, requested = float(payload.get("liftHeightM", 0)), float(payload.get("requestedHeightM", 0))
    battery = float(payload.get("batteryPercent", 0))
    delta = requested - current
    reasons = []
    if battery < 20: reasons.append("LOW_BATTERY")
    if not 0.4 <= requested <= 2.4: reasons.append("HEIGHT_OUT_OF_RANGE")
    if abs(delta) > 0.02 and payload.get("driveState") != "HOLD": reasons.append("DRIVE_NOT_HELD")
    accepted = not reasons
    command = "BLOCKED" if not accepted else ("HOLD" if abs(delta) <= 0.02 else ("LIFT" if delta > 0 else "LOWER"))
    return {"component": "agerobotics/high-lift-mobile-platform", "accepted": accepted,
            "status": "PLATFORM_READY" if accepted else "INTERLOCK", "target": "mcu",
            "command": command, "deltaM": round(delta, 3), "blockingReasons": reasons,
            "batteryPercent": battery}
