package com.correx.core.sessions.projections.replay

import com.correx.core.events.stores.EventStore
import com.correx.core.events.types.SessionId
import com.correx.core.sessions.projections.DefaultStateBuilder
import com.correx.core.sessions.projections.Projection

class DefaultEventReplayer<S>(
    private val store: EventStore,
    private val projection: Projection<S>
) : EventReplayer<S> {

    override fun rebuild(sessionId: SessionId): S {
        val events = store.read(sessionId)

        return DefaultStateBuilder(projection)
            .build(events)
    }
}
