//
        // Event data
        //

        internal static EventData GetAreaEventData(
            this EventStoreContext context,
            Event e,
            TimelinePosition cause,
            DateTimeOffset when,
            DateTimeOffset?whenOccurs,
            Id eventId,
            Id commandId,
            Id userId,
            FlowKey topic,
            Many <FlowKey> routes)
        {
            var type = context.GetEventType(e);

            var metadata = new AreaEventMetadata
            {
                Cause      = cause,
                When       = when,
                WhenOccurs = whenOccurs,
                CommandId  = commandId,
                UserId     = userId,
                Topic      = topic
            };

            metadata.ApplyRoutes(type, routes);

            return(new EventData(
                       eventId.IsUnassigned ? Guid.NewGuid() : Guid.Parse(eventId.ToString()),
                       type.ToString(),
                       isJson: true,
                       data: context.ToJson(e),
                       metadata: context.ToJson(metadata)));
        }
        //
        // Reads
        //

        internal static TimelinePoint ReadAreaPoint(this EventStoreContext context, ResolvedEvent e, AreaEventMetadata metadata)
        {
            var type = context.ReadEventType(e);

            return(new TimelinePoint(
                       new TimelinePosition(e.Event.EventNumber),
                       metadata.Cause,
                       type,
                       metadata.When,
                       metadata.WhenOccurs,
                       Id.From(e.Event.EventId),
                       metadata.CommandId,
                       metadata.UserId,
                       metadata.Topic,
                       metadata.GetRoutes(context.Area).ToMany(),
                       () =>
            {
                var instance = context.ReadEvent(e, type);

                Event.Traits.When.Set(instance, metadata.When);
                Event.Traits.WhenOccurs.Set(instance, metadata.WhenOccurs);
                Event.Traits.CommandId.Set(instance, metadata.CommandId);
                Event.Traits.UserId.Set(instance, metadata.UserId);

                return instance;
            }));
        }