import com.correx.core.context.model.TokenBudget
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class TokenBudgetEnforcementTest {

    @Test
    fun `remaining equals limit minus used`() {
        val budget = TokenBudget(limit = 1000, used = 300)
        assertEquals(700, budget.remaining)
    }

    @Test
    fun `canFit returns true when tokens fit`() {
        val budget = TokenBudget(limit = 500, used = 100)
        assertTrue(budget.canFit(400))
    }

    @Test
    fun `canFit returns false when over budget`() {
        val budget = TokenBudget(limit = 500, used = 400)
        assertFalse(budget.canFit(200))
    }

    @Test
    fun `consume returns new instance with updated used`() {
        val original = TokenBudget(limit = 1000, used = 0)
        val after = original.consume(250)
        assertEquals(0, original.used)
        assertEquals(250, after.used)
        assertEquals(750, after.remaining)
    }

    @Test
    fun `fully exhausted budget cannot fit any tokens`() {
        val budget = TokenBudget(limit = 100, used = 100)
        assertFalse(budget.canFit(1))
        assertEquals(0, budget.remaining)
    }
}
