package com.correx.testing.kernel

import com.correx.core.events.orchestration.OrchestrationState
import com.correx.core.events.orchestration.OrchestrationStatus
import com.correx.core.events.types.SessionId
import com.correx.core.events.types.StageId
import com.correx.core.sessions.SessionState
import com.correx.core.sessions.SessionStatus
import com.correx.core.sessions.projections.replay.EventReplayer
import kotlinx.datetime.Clock

class MockOrchestrationEventReplayer : EventReplayer<OrchestrationState> {
    private val states = mutableMapOf<SessionId, OrchestrationState>()

    fun setSessionState(sessionId: SessionId, state: OrchestrationState) {
        states[sessionId] = state
    }

    override fun rebuild(sessionId: SessionId): OrchestrationState {
        return states[sessionId] ?: OrchestrationState(
            status = OrchestrationStatus.RUNNING,
            currentStageId = StageId("stage-1"),
        )
    }
}

class MockSessionEventReplayer : EventReplayer<SessionState> {
    private val states = mutableMapOf<SessionId, SessionState>()

    fun setSessionState(sessionId: SessionId, state: SessionState) {
        states[sessionId] = state
    }

    override fun rebuild(sessionId: SessionId): SessionState {
        return states[sessionId] ?: SessionState(
            status = SessionStatus.ACTIVE,
            createdAt = Clock.System.now(),
            updatedAt = Clock.System.now(),
            invalidTransitions = 0,
        )
    }
}
