import warnings


def drop_duplicate_messages(updates):
    """
    Given a list of feed updates, drops updates from the feed which appear more than once 
    (have the same timestamp). This would occur when the feed returns stale data.
    """
    parse_errors = []

    if updates == []:
        return [], []

    ts_prior = updates[0]['header']['timestamp']
    out = [updates[0]]

    for idx in range(1, len(updates)):
        ts_curr = updates[idx]['header']['timestamp']
        if ts_curr == ts_prior:
            warnings.warn(
                f"There are multiple messages in the GTFS-RT update for timestamp "
                f"{updates[idx]['header']['timestamp']}. The duplicate updates were removed "
                f"during pre-processing."
            )
            parse_errors.append({
                'type': 'feed_updates_with_duplicate_timestamps',
                'details': {
                    'update_timestamp': updates[idx]['header']['timestamp'],
                    'message_index': idx,
                    'message_body': updates[idx]
                }
            })
        else:
            out.append(updates[idx])
        ts_prior = ts_curr

    return out, parse_errors