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.ApprovalGrant
import com.correx.core.approvals.model.ApprovalScopeIdentity
import com.correx.core.events.types.SessionId
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 ApprovalEngineDeterminismTest {

    private val engine = DefaultApprovalEngine()

    @Test
    fun `identical inputs produce identical decisions`() {
        val request = request("r1", Tier.T2)
        val identity = ApprovalScopeIdentity(SessionId("s1"), null, null)
        val context = ApprovalContext(identity, ApprovalMode.AUTO)
        val grants = emptyList<ApprovalGrant>()
        val now = Instant.parse("2026-01-01T00:00:01Z")

        val d1 = engine.evaluate(request, context, grants, now)
        val d2 = engine.evaluate(request, context, grants, now)

        assertEquals(d1, d2)
    }

    @Test
    fun `different requests produce different decision IDs`() {
        val request1 = request("r1", Tier.T2)
        val request2 = request("r2", Tier.T2)
        val identity = ApprovalScopeIdentity(SessionId("s1"), null, null)
        val context = ApprovalContext(identity, ApprovalMode.AUTO)
        val now = Instant.parse("2026-01-01T00:00:01Z")

        val d1 = engine.evaluate(request1, context, emptyList(), now)
        val d2 = engine.evaluate(request2, context, emptyList(), now)

        assertNotEquals(d1.id, d2.id)
    }
}
