Build challenge: build an order processing system
Asked in the build challenge stage. Implement a function that processes orders sequentially against available inventory.
Each order contains an id and item records with sku, quantity, and unit_price. Accept an order only when every requested SKU has sufficient inventory, then decrement all requested stock atomically. Reject duplicate order IDs and orders with insufficient inventory without changing stock. Return results in input order and the remaining inventory.
Input: orders is a list of dictionaries and inventory is a SKU-to-quantity dictionary. Output: return {"results": [...], "inventory": {...}}; each result contains order_id, status, and total, with an optional reason for rejection.
def process_orders(orders, inventory):