def do_schedule_messages(messages: Sequence[Mapping[(str, Any)]]) -> List[int]:
    scheduled_messages: List[ScheduledMessage] = []
    for message in messages:
        scheduled_message = ScheduledMessage()
        scheduled_message.sender = message['message'].sender
        scheduled_message.recipient = message['message'].recipient
        topic_name = message['message'].topic_name()
        scheduled_message.set_topic_name(topic_name=topic_name)
        scheduled_message.content = message['message'].content
        scheduled_message.sending_client = message['message'].sending_client
        scheduled_message.stream = message['stream']
        scheduled_message.realm = message['realm']
        scheduled_message.scheduled_timestamp = message['deliver_at']
        if (message['delivery_type'] == 'send_later'):
            scheduled_message.delivery_type = ScheduledMessage.SEND_LATER
        elif (message['delivery_type'] == 'remind'):
            scheduled_message.delivery_type = ScheduledMessage.REMIND
        scheduled_messages.append(scheduled_message)
    ScheduledMessage.objects.bulk_create(scheduled_messages)
    return [scheduled_message.id for scheduled_message in scheduled_messages]
def do_schedule_messages(messages: Sequence[Mapping[(str, Any)]]) -> List[int]:
    scheduled_messages: List[ScheduledMessage] = []
    for message in messages:
        scheduled_message = ScheduledMessage()
        scheduled_message.sender = message['message'].sender
        scheduled_message.recipient = message['message'].recipient
        topic_name = message['message'].topic_name()
        scheduled_message.set_topic_name(topic_name=topic_name)
        scheduled_message.content = message['message'].content
        scheduled_message.sending_client = message['message'].sending_client
        scheduled_message.stream = message['stream']
        scheduled_message.realm = message['realm']
        scheduled_message.scheduled_timestamp = message['deliver_at']
        if (message['delivery_type'] == 'send_later'):
            scheduled_message.delivery_type = ScheduledMessage.SEND_LATER
        elif (message['delivery_type'] == 'remind'):
            scheduled_message.delivery_type = ScheduledMessage.REMIND
        scheduled_messages.append(scheduled_message)
    ScheduledMessage.objects.bulk_create(scheduled_messages)
    return [scheduled_message.id for scheduled_message in scheduled_messages]