package com.correx.testing.contracts.model

import com.correx.core.approvals.Tier
import com.correx.core.approvals.domain.DefaultApprovalEngine
import com.correx.core.approvals.model.ApprovalContext
import com.correx.core.approvals.model.ApprovalScopeIdentity
import com.correx.core.events.types.ProjectId
import com.correx.core.events.types.SessionId
import com.correx.core.events.types.StageId
import com.correx.core.sessions.ApprovalMode
import com.correx.testing.fixtures.request
import kotlinx.datetime.Instant
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Test

class ContextSnapshotTest {

    @Test
    fun `decision contains snapshot, not live context`() {
        val engine = DefaultApprovalEngine()
        val identity = ApprovalScopeIdentity(SessionId("s1"), StageId("st1"), ProjectId("p1"))
        val mode = ApprovalMode.AUTO
        val context = ApprovalContext(identity, mode)
        val now = Instant.parse("2026-01-01T00:00:01Z")

        val decision = engine.evaluate(request("r1", Tier.T2), context, emptyList(), now)

        assertEquals(identity, decision.contextSnapshot.identity)
        assertEquals(mode, decision.contextSnapshot.mode)
    }

    @Test
    fun `snapshot does not change after decision`() {
        val engine = DefaultApprovalEngine()
        val identity = ApprovalScopeIdentity(SessionId("s1"), null, null)
        val context = ApprovalContext(identity, ApprovalMode.PROMPT)
        val now = Instant.parse("2026-01-01T00:00:01Z")

        val decision = engine.evaluate(request("r1", Tier.T2), context, emptyList(), now)
        val anotherContext = context.copy(mode = ApprovalMode.YOLO)
        assertNotEquals(anotherContext.mode, decision.contextSnapshot.mode)
    }
}
