from __future__ import annotations


def execute(payload: dict) -> dict:
    valid = []
    for point in payload.get("points", []):
        try:
            valid.append({"class": str(point["class"]), "x": float(point["x"]), "y": float(point["y"]), "z": float(point["z"])})
        except (KeyError, TypeError, ValueError):
            continue
    counts = {}
    for point in valid: counts[point["class"]] = counts.get(point["class"], 0) + 1
    bounds = None if not valid else {axis: [min(point[axis] for point in valid), max(point[axis] for point in valid)] for axis in ("x", "y", "z")}
    obstacles = [{"x": point["x"], "y": point["y"], "z": point["z"]} for point in valid if point["class"] == "obstacle"]
    accepted = bool(valid)
    return {"component": "unist/crop-structure-mapping", "accepted": accepted,
            "status": "MAP_READY" if accepted else "NO_POINTS", "target": "vpu",
            "mapId": str(payload.get("mapId", "unknown")), "counts": counts,
            "bounds": bounds, "obstacles": obstacles}
