package com.correx.core.kernel.orchestration

import com.correx.core.validation.artifact.ArtifactFailure
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class ArtifactPolicyDecisionTest {

    private fun decideFresh(f: ArtifactFailure) =
        decide(f, attemptsSoFar = 0, maxAttempts = Int.MAX_VALUE, hasApprover = false)

    @Test
    fun `unsafe always aborts, even with budget and approver`() {
        assertEquals(ArtifactPolicyDecision.Abort, decide(ArtifactFailure.UNSAFE, 0, 5, hasApprover = true))
    }

    @Test
    fun `schema and formatting retry the producer`() {
        assertEquals(ArtifactPolicyDecision.RetryProducer, decideFresh(ArtifactFailure.SCHEMA))
        assertEquals(ArtifactPolicyDecision.RetryProducer, decideFresh(ArtifactFailure.FORMATTING))
        assertEquals(ArtifactPolicyDecision.RetryProducer, decideFresh(ArtifactFailure.CONTRADICTORY))
    }

    @Test
    fun `missing info regenerates artifact-only on first attempt then retries producer`() {
        assertEquals(ArtifactPolicyDecision.RegenerateArtifactOnly, decide(ArtifactFailure.MISSING_INFO, 0, 5, false))
        assertEquals(ArtifactPolicyDecision.RetryProducer, decide(ArtifactFailure.MISSING_INFO, 1, 5, false))
    }

    @Test
    fun `exhausted budget escalates with approver, aborts without`() {
        assertEquals(ArtifactPolicyDecision.EscalateHuman, decide(ArtifactFailure.SCHEMA, 3, 3, hasApprover = true))
        assertEquals(ArtifactPolicyDecision.Abort, decide(ArtifactFailure.SCHEMA, 3, 3, hasApprover = false))
    }
}
