You are given an unsorted list of event records for one delivery driver and a list of peak pay periods. Each event is a JSON-like Python dictionary with fields such as 'order_id', 'event_type', 'timestamp', and sometimes 'base_rate_per_minute'. A valid order interval is defined by exactly one 'start' event and exactly one 'complete' event for the same order, with complete_timestamp > start_timestamp. During peak periods, the driver's pay rate is doubled. If an order interval partially overlaps a peak period, only the overlapping portion gets double pay. Treat all intervals as half-open ranges [start, end). Peak periods may overlap each other; overlapping or adjacent peak periods should be merged into one continuous peak range. Ignore invalid peak periods where start >= end. Ignore malformed orders entirely: missing start or completion, duplicate start or completion, a missing rate on the start event, or invalid ordering.
Examples
Input: ([{'order_id': 'A', 'event_type': 'start', 'timestamp': 0, 'base_rate_per_minute': 3}, {'order_id': 'A', 'event_type': 'complete', 'timestamp': 10}], [(2, 5), (7, 9)])
Expected Output: 45
Explanation: Order A lasts 10 minutes at rate 3. Peak overlap is 3 minutes from [2,5) and 2 minutes from [7,9), total 5 peak minutes. Pay = 3 * (10 + 5) = 45.
Input: ([{'order_id': 'A', 'event_type': 'start', 'timestamp': 1, 'base_rate_per_minute': 2}, {'order_id': 'A', 'event_type': 'complete', 'timestamp': 8}, {'order_id': 'B', 'event_type': 'start', 'timestamp': 6, 'base_rate_per_minute': 1}, {'order_id': 'B', 'event_type': 'complete', 'timestamp': 10}], [(0, 3), (2, 6)])
Expected Output: 28
Explanation: Peak ranges merge to [0,6). Order A overlaps 5 peak minutes, so pay is 2 * (7 + 5) = 24. Order B is [6,10), which does not overlap [0,6) under half-open interval rules, so it pays 4. Total = 28.
Input: ([{'order_id': 'A', 'event_type': 'start', 'timestamp': 5, 'base_rate_per_minute': 2}, {'order_id': 'A', 'event_type': 'complete', 'timestamp': 10}, {'order_id': 'B', 'event_type': 'start', 'timestamp': 4, 'base_rate_per_minute': 3}, {'order_id': 'B', 'event_type': 'complete', 'timestamp': 3}, {'order_id': 'C', 'event_type': 'start', 'timestamp': 0, 'base_rate_per_minute': 1}], [(6, 8), (9, 9), (12, 11)])
Expected Output: 14
Explanation: Only A is a valid order. Only peak period (6,8) is valid. Order A has duration 5 and peak overlap 2, so pay is 2 * (5 + 2) = 14.
Input: ([], [(0, 5)])
Expected Output: 0
Explanation: No events means no pay.
Input: ([{'order_id': 'Z', 'event_type': 'start', 'timestamp': 2, 'base_rate_per_minute': 5}, {'order_id': 'Z', 'event_type': 'complete', 'timestamp': 6}], [])
Expected Output: 20
Explanation: With no peak periods, the calculation falls back to normal base pay: (6 - 2) * 5 = 20.